Class: Eco::API::Session::Batch::Jobs
Instance Attribute Summary collapse
#api, #config, #environment, #file_manager, #logger, #session
Instance Method Summary
collapse
#enviro=, #fatal, #fm, #mailer, #mailer?, #s3uploader, #s3uploader?, #sftp, #sftp?
Constructor Details
#initialize(e, name:) ⇒ Jobs
Returns a new instance of Jobs.
9
10
11
12
13
|
# File 'lib/eco/api/session/batch/jobs.rb', line 9
def initialize(e, name:)
super(e)
@name = name
reset
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/eco/api/session/batch/jobs.rb', line 7
def name
@name
end
|
Instance Method Details
#[](name) ⇒ Object
37
38
39
|
# File 'lib/eco/api/session/batch/jobs.rb', line 37
def [](name)
@jobs[name]
end
|
#add(job) ⇒ Object
60
61
62
63
64
|
# File 'lib/eco/api/session/batch/jobs.rb', line 60
def add(job)
fatal "Expected Eco::API::Session::Batch::Job object. Given #{job.class}" unless job.is_a?(Eco::API::Session::Batch::Job)
@jobs[job.name] = job
@callbacks[job] = Proc.new if block_given?
end
|
#each(&block) ⇒ Object
28
29
30
31
|
# File 'lib/eco/api/session/batch/jobs.rb', line 28
def each(&block)
return to_enum(:each) unless block
items.each(&block)
end
|
#empty? ⇒ Boolean
24
25
26
|
# File 'lib/eco/api/session/batch/jobs.rb', line 24
def empty?
count == 0
end
|
#errors? ⇒ Boolean
99
100
101
|
# File 'lib/eco/api/session/batch/jobs.rb', line 99
def errors?
any? {|job| job.errors?}
end
|
#exists?(name) ⇒ Boolean
41
42
43
|
# File 'lib/eco/api/session/batch/jobs.rb', line 41
def exists?(name)
@jobs.key?(name)
end
|
#find_jobs(type:) ⇒ Object
82
83
84
85
86
|
# File 'lib/eco/api/session/batch/jobs.rb', line 82
def find_jobs(type:)
each_with_object([]) do |job, jbs|
jbs.push(job) if job.type == type
end
end
|
#items ⇒ Object
33
34
35
|
# File 'lib/eco/api/session/batch/jobs.rb', line 33
def items
@jobs.values
end
|
#job(name, type: nil, sets: nil, usecase: nil, &block) ⇒ Object
45
46
47
48
49
50
|
# File 'lib/eco/api/session/batch/jobs.rb', line 45
def job(name, type: nil, sets: nil, usecase: nil, &block)
new(name, type: type, sets: sets, usecase: usecase, &block) unless exists?(name)
self[name].tap do |job|
block.call(job) if block
end
end
|
#launch(simulate: false) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/eco/api/session/batch/jobs.rb', line 70
def launch(simulate: false)
each do |job|
if job.pending?
status[job] = job_status = job.launch(simulate: simulate)
callback = @callbacks[job]
callback.call(job, job_status) if callback
end
end
return status
end
|
#length ⇒ Object
20
21
22
|
# File 'lib/eco/api/session/batch/jobs.rb', line 20
def length
count
end
|
#new(name, type:, sets:, usecase: nil, &block) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/eco/api/session/batch/jobs.rb', line 52
def new(name, type:, sets:, usecase: nil, &block)
fatal "Can't create job named '#{name}' because it already exists." if exists?(name)
Batch::Job.new(enviro, name: name, type: type, sets: sets, usecase: usecase).tap do |job|
add(job, &block)
end
end
|
#pending? ⇒ Boolean
66
67
68
|
# File 'lib/eco/api/session/batch/jobs.rb', line 66
def pending?
any? {|job| job.pending?}
end
|
#reset ⇒ Object
15
16
17
18
|
# File 'lib/eco/api/session/batch/jobs.rb', line 15
def reset
@jobs = {}
@callbacks = {}
end
|
#status ⇒ Object
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/eco/api/session/batch/jobs.rb', line 88
def status
if block_given?
status.each do |job, job_status|
yield(job, job_status)
end
self
else
@jobs_status ||= {}
end
end
|
#summary ⇒ Object
103
104
105
106
107
|
# File 'lib/eco/api/session/batch/jobs.rb', line 103
def summary
[].tap do |msg|
map {|job| msg << job.summary}
end.join("\n")
end
|