Class: Swineherd::Job

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

Overview

Job class is at its core a rake task

Instance Method Summary collapse

Constructor Details

#initialize(job_id, &blk) ⇒ Job

Initialize job, fill variables, and create rake task



11
12
13
14
15
16
17
18
19
# File 'lib/swineherd/workflow/job.rb', line 11

def initialize job_id, &blk
  @job_id       = job_id
  @name         = ''
  @dependencies = []
  @script       = ''
  self.instance_eval(&blk)
  raketask
  handle_dependencies
end

Instance Method Details

#cmdObject



47
48
49
# File 'lib/swineherd/workflow/job.rb', line 47

def cmd
  @script.cmd
end

#dependencies(dependencies = nil) ⇒ Object

An array of job names as dependencies



37
38
39
40
# File 'lib/swineherd/workflow/job.rb', line 37

def dependencies dependencies = nil
  return @dependencies unless dependencies
  @dependencies = dependencies
end

#handle_dependenciesObject



42
43
44
45
# File 'lib/swineherd/workflow/job.rb', line 42

def handle_dependencies
  return if dependencies.empty?
  task name => dependencies
end

#name(name = nil) ⇒ Object

Will be the name of the rake task



24
25
26
27
# File 'lib/swineherd/workflow/job.rb', line 24

def name name = nil
  return @name unless name
  @name = name
end

#raketaskObject

Every job is compiled into a rake task



54
55
56
57
58
# File 'lib/swineherd/workflow/job.rb', line 54

def raketask
  task name do
    @script.run
  end
end

#script(script = nil) ⇒ Object



29
30
31
32
# File 'lib/swineherd/workflow/job.rb', line 29

def script script = nil
  return @script unless script
  @script = script
end