Class: BatchManager::BatchStatus
- Inherits:
-
Object
- Object
- BatchManager::BatchStatus
- Includes:
- Utils
- Defined in:
- lib/batch_manager/batch_status.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#group_name ⇒ Object
Returns the value of attribute group_name.
-
#managed ⇒ Object
Returns the value of attribute managed.
-
#name ⇒ Object
Returns the value of attribute name.
-
#times_limit ⇒ Object
Returns the value of attribute times_limit.
Instance Method Summary collapse
- #can_run? ⇒ Boolean
-
#initialize(path) ⇒ BatchStatus
constructor
A new instance of BatchStatus.
- #managed? ⇒ Boolean
- #parse_batch_content(line) ⇒ Object
- #schema_batch ⇒ Object
- #update_schema ⇒ Object
Methods included from Utils
Constructor Details
#initialize(path) ⇒ BatchStatus
Returns a new instance of BatchStatus.
6 7 8 9 10 11 12 13 |
# 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 |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
4 5 6 |
# File 'lib/batch_manager/batch_status.rb', line 4 def created_at @created_at end |
#group_name ⇒ Object
Returns the value of attribute group_name.
4 5 6 |
# File 'lib/batch_manager/batch_status.rb', line 4 def group_name @group_name end |
#managed ⇒ Object
Returns the value of attribute managed.
4 5 6 |
# File 'lib/batch_manager/batch_status.rb', line 4 def managed @managed end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/batch_manager/batch_status.rb', line 4 def name @name end |
#times_limit ⇒ Object
Returns the value of attribute times_limit.
4 5 6 |
# File 'lib/batch_manager/batch_status.rb', line 4 def times_limit @times_limit end |
Instance Method Details
#can_run? ⇒ Boolean
37 38 39 |
# 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? ⇒ Boolean
33 34 35 |
# File 'lib/batch_manager/batch_status.rb', line 33 def managed? @managed end |
#parse_batch_content(line) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 ⇒ Object
15 16 17 |
# File 'lib/batch_manager/batch_status.rb', line 15 def schema_batch BatchManager::SchemaBatch.find_by_name(@name) if @name end |
#update_schema ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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 |