Class: Itiel::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/itiel/job.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/itiel/job.rb', line 3

def block
  @block
end

Class Method Details

.define(&block) ⇒ Object

Use it to define the job steps and then run the job at a later date.

It returns an instance of a job, you can call run! on that instance later to actually run the steps defined on the block of the job

Uses the same syntax as run:

job = Itiel::Job.define do |job|
  job.step @source => @destination
end

job.run!

Or

job = Itiel::Job.define do |job|
  job.step @source
  job.step @destination

  ...
end

job.run!


68
69
70
# File 'lib/itiel/job.rb', line 68

def self.define(&block)
  self.new(&block)
end

.run {|self.new| ... } ⇒ Object

Pass a block to this method to process the ETL steps in order

Understands a single line per step:

Itiel::Job.run do |job|
  job.step @source
  job.step @destination

  ...
end

In this case the @source.output is sent to the @destination’s input A third step on the list would send the @destination’s output to its input

Another way to do this is by passing hashes to the step method:

Itiel::Job.run do |job|
  job.step @source => @destination
end

You want to use this sintax when creating more complex flows. For example, you could send a step output to several inputs

Itiel::Job.run do |job|
  job.step @source => [ @destination, @second_destination ]
end

Yields:

  • (self.new)


37
38
39
40
41
# File 'lib/itiel/job.rb', line 37

def self.run(&block)
  Itiel::Logger.log_start_job(self)
  yield self.new
  Itiel::Logger.log_end_job(self)
end

Instance Method Details

#run!Object

Use it to run the steps on a previously defined Job



75
76
77
78
79
# File 'lib/itiel/job.rb', line 75

def run!
  Itiel::Logger.log_start_job(self)
  self.block.call(self)
  Itiel::Logger.log_end_job(self)
end

#step(*args) ⇒ Object

Call inside the run block to denote a data flow



84
85
86
87
88
89
90
# File 'lib/itiel/job.rb', line 84

def step(*args)
  if args[0].is_a?(Hash)
    hash_based_step(args[0])
  else
    single_line_step(args[0])
  end
end