Class: Drudgery::Job
- Inherits:
-
Object
- Object
- Drudgery::Job
- Defined in:
- lib/drudgery/job.rb
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
Returns the value of attribute batch_size.
-
#completed_at ⇒ Object
readonly
Returns the value of attribute completed_at.
-
#extractor ⇒ Object
Returns the value of attribute extractor.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#loader ⇒ Object
Returns the value of attribute loader.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#transformer ⇒ Object
Returns the value of attribute transformer.
Instance Method Summary collapse
- #extract(*args) {|extractor| ... } ⇒ Object
-
#initialize(options = {}) ⇒ Job
constructor
A new instance of Job.
- #load(*args) {|loader| ... } ⇒ Object
- #name ⇒ Object
- #perform ⇒ Object
- #record_count ⇒ Object
- #transform(transformer = Drudgery::Transformer.new, &processor) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Job
Returns a new instance of Job.
6 7 8 9 10 11 12 13 14 |
# File 'lib/drudgery/job.rb', line 6 def initialize(={}) @id = Time.now.nsec @extractor = [:extractor] @loader = [:loader] @transformer = [:transformer] @batch_size = [:batch_size] || 1000 @records = [] end |
Instance Attribute Details
#batch_size ⇒ Object
Returns the value of attribute batch_size.
4 5 6 |
# File 'lib/drudgery/job.rb', line 4 def batch_size @batch_size end |
#completed_at ⇒ Object (readonly)
Returns the value of attribute completed_at.
3 4 5 |
# File 'lib/drudgery/job.rb', line 3 def completed_at @completed_at end |
#extractor ⇒ Object
Returns the value of attribute extractor.
4 5 6 |
# File 'lib/drudgery/job.rb', line 4 def extractor @extractor end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/drudgery/job.rb', line 3 def id @id end |
#loader ⇒ Object
Returns the value of attribute loader.
4 5 6 |
# File 'lib/drudgery/job.rb', line 4 def loader @loader end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
3 4 5 |
# File 'lib/drudgery/job.rb', line 3 def started_at @started_at end |
#transformer ⇒ Object
Returns the value of attribute transformer.
4 5 6 |
# File 'lib/drudgery/job.rb', line 4 def transformer @transformer end |
Instance Method Details
#extract(*args) {|extractor| ... } ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/drudgery/job.rb', line 26 def extract(*args) if args.first.kind_of?(Symbol) extractor = Drudgery::Extractors.instantiate(*args) else extractor = args.first end yield extractor if block_given? @extractor = extractor end |
#load(*args) {|loader| ... } ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/drudgery/job.rb', line 44 def load(*args) if args.first.kind_of?(Symbol) loader = Drudgery::Loaders.instantiate(*args) else loader = args.first end yield loader if block_given? @loader = loader end |
#name ⇒ Object
16 17 18 |
# File 'lib/drudgery/job.rb', line 16 def name "#{@extractor.name} => #{@loader.name}" end |
#perform ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/drudgery/job.rb', line 56 def perform @started_at = Time.now Drudgery.notify :before_job, self extract_records do |record| @records << record if @records.size == @batch_size load_records end end load_records @completed_at = Time.now Drudgery.notify :after_job, self end |
#record_count ⇒ Object
20 21 22 23 24 |
# File 'lib/drudgery/job.rb', line 20 def record_count if @extractor @record_count ||= @extractor.record_count end end |
#transform(transformer = Drudgery::Transformer.new, &processor) ⇒ Object
38 39 40 41 42 |
# File 'lib/drudgery/job.rb', line 38 def transform(transformer=Drudgery::Transformer.new, &processor) transformer.register(processor) if processor @transformer = transformer end |