class BatchManager::BatchStatus

Attributes

created_at[RW]
group_name[RW]
managed[RW]
name[RW]
times_limit[RW]

Public Class Methods

new(path) click to toggle source
# File lib/batch_manager/batch_status.rb, line 6
def initialize(path)
  @name = batch_name(path)
  File.open path do |f|
    f.each_line do |line|
      parse_batch_content line
    end
  end
end

Public Instance Methods

can_run?() click to toggle source
# File lib/batch_manager/batch_status.rb, line 37
def can_run?
  @times_limit.to_i <= 0 || @times_limit > schema_batch.try(:ran_times).to_i
end
managed?() click to toggle source
# File lib/batch_manager/batch_status.rb, line 33
def managed?
  @managed
end
parse_batch_content(line) click to toggle source
# File lib/batch_manager/batch_status.rb, line 41
def parse_batch_content(line)
  if line.start_with?("#")
    @managed = true if line.include?(BatchManager.signal)
    if managed?
      if line.include?("=times_limit:")
        @times_limit = line.sub(/#\s*=times_limit:/, "").strip.to_i
      elsif line.include?("=created_at:")
        @created_at = Time.parse(line.sub(/#\s*=created_at:/, "").strip)
      elsif line.include?("=group_name:")
        @group_name = line.sub(/#\s*=group_name:/, "").strip
      end
    end
  end
end
schema_batch() click to toggle source
# File lib/batch_manager/batch_status.rb, line 15
def schema_batch
  BatchManager::SchemaBatch.find_by_name(@name) if @name
end
update_schema() click to toggle source
# File lib/batch_manager/batch_status.rb, line 19
def update_schema
  if managed?
    if schema_batch
      schema_batch.increment!(:ran_times)
    else
      BatchManager::SchemaBatch.create! do |s|
        s.name = @name
        s.ran_times = 1
        s.last_ran_at = Time.now
      end
    end
  end
end