Class: Chronicle::ETL::JobLog
- Inherits:
-
Object
- Object
- Chronicle::ETL::JobLog
- Extended by:
- Forwardable
- Defined in:
- lib/chronicle/etl/job_log.rb
Overview
A record of what happened in the running of a job. We're interested in tracking when it ran, if it was successful, and what the latest record we found is (to use as a cursor for the next time)
Instance Attribute Summary collapse
-
#finished_at ⇒ Object
Returns the value of attribute finished_at.
-
#highest_timestamp ⇒ Object
Returns the value of attribute highest_timestamp.
-
#job ⇒ Object
Returns the value of attribute job.
-
#job_id ⇒ Object
Returns the value of attribute job_id.
-
#last_id ⇒ Object
Returns the value of attribute last_id.
-
#num_records_processed ⇒ Object
Returns the value of attribute num_records_processed.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
-
#success ⇒ Object
Returns the value of attribute success.
Class Method Summary collapse
-
.build_from_serialized(attrs) ⇒ Object
Create a new JobLog and set its instance variables from a serialized hash.
Instance Method Summary collapse
- #duration ⇒ Object
- #error ⇒ Object
-
#finish ⇒ Object
Indicate that a job has finished.
-
#initialize {|_self| ... } ⇒ JobLog
constructor
Create a new JobLog for a given Job.
-
#log_transformation(_transformer) ⇒ Object
Log the result of a single transformation in a job.
-
#serialize ⇒ Object
Take a JobLog's instance variables and turn them into a hash representation.
-
#start ⇒ Object
Indicate that a job has started.
Constructor Details
#initialize {|_self| ... } ⇒ JobLog
Create a new JobLog for a given Job
23 24 25 26 27 |
# File 'lib/chronicle/etl/job_log.rb', line 23 def initialize @num_records_processed = 0 @success = false yield self if block_given? end |
Instance Attribute Details
#finished_at ⇒ Object
Returns the value of attribute finished_at.
11 12 13 |
# File 'lib/chronicle/etl/job_log.rb', line 11 def finished_at @finished_at end |
#highest_timestamp ⇒ Object
Returns the value of attribute highest_timestamp.
11 12 13 |
# File 'lib/chronicle/etl/job_log.rb', line 11 def @highest_timestamp end |
#job ⇒ Object
Returns the value of attribute job.
11 12 13 |
# File 'lib/chronicle/etl/job_log.rb', line 11 def job @job end |
#job_id ⇒ Object
Returns the value of attribute job_id.
11 12 13 |
# File 'lib/chronicle/etl/job_log.rb', line 11 def job_id @job_id end |
#last_id ⇒ Object
Returns the value of attribute last_id.
11 12 13 |
# File 'lib/chronicle/etl/job_log.rb', line 11 def last_id @last_id end |
#num_records_processed ⇒ Object
Returns the value of attribute num_records_processed.
11 12 13 |
# File 'lib/chronicle/etl/job_log.rb', line 11 def num_records_processed @num_records_processed end |
#started_at ⇒ Object
Returns the value of attribute started_at.
11 12 13 |
# File 'lib/chronicle/etl/job_log.rb', line 11 def started_at @started_at end |
#success ⇒ Object
Returns the value of attribute success.
11 12 13 |
# File 'lib/chronicle/etl/job_log.rb', line 11 def success @success end |
Class Method Details
.build_from_serialized(attrs) ⇒ Object
Create a new JobLog and set its instance variables from a serialized hash
82 83 84 85 86 87 88 89 90 |
# File 'lib/chronicle/etl/job_log.rb', line 82 def self.build_from_serialized(attrs) attrs.delete(:id) new do |job_log| attrs.each do |key, value| setter = :"#{key}=" job_log.send(setter, value) end end end |
Instance Method Details
#duration ⇒ Object
62 63 64 65 66 |
# File 'lib/chronicle/etl/job_log.rb', line 62 def duration return unless @finished_at && @started_at @finished_at - @started_at end |
#error ⇒ Object
53 54 55 |
# File 'lib/chronicle/etl/job_log.rb', line 53 def error @finished_at = Time.now end |
#finish ⇒ Object
Indicate that a job has finished
48 49 50 51 |
# File 'lib/chronicle/etl/job_log.rb', line 48 def finish @finished_at = Time.now @success = true end |
#log_transformation(_transformer) ⇒ Object
Log the result of a single transformation in a job
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/chronicle/etl/job_log.rb', line 31 def log_transformation(_transformer) # @last_id = transformer.id if transformer.id # Save the highest timestamp that we've encountered so far # @highest_timestamp = [transformer.timestamp, @highest_timestamp].compact.max if transformer.timestamp # TODO: a transformer might yield nil. We might also want certain transformers to explode # records into multiple new ones. Therefore, this this variable will need more subtle behaviour @num_records_processed += 1 end |
#serialize ⇒ Object
Take a JobLog's instance variables and turn them into a hash representation
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/chronicle/etl/job_log.rb', line 69 def serialize { job_id: @job_id, last_id: @last_id, highest_timestamp: @highest_timestamp, num_records_processed: @num_records_processed, started_at: @started_at, finished_at: @finished_at, success: @success } end |
#start ⇒ Object
Indicate that a job has started
43 44 45 |
# File 'lib/chronicle/etl/job_log.rb', line 43 def start @started_at = Time.now end |