Class: Burst::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/burst/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workflow) ⇒ Manager

Returns a new instance of Manager.



5
6
7
# File 'lib/burst/manager.rb', line 5

def initialize(workflow)
  @workflow = workflow
end

Instance Attribute Details

#workflowObject

Returns the value of attribute workflow.



3
4
5
# File 'lib/burst/manager.rb', line 3

def workflow
  @workflow
end

Instance Method Details

#enqueue_job!(job) ⇒ Object



19
20
21
22
23
24
# File 'lib/burst/manager.rb', line 19

def enqueue_job!(job)
  job.enqueue!
  job.save! do
    Burst::Worker.perform_later(workflow.id, job.id)
  end
end

#enqueue_outgoing_jobs(job) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/burst/manager.rb', line 71

def enqueue_outgoing_jobs(job)
  job.outgoing.each do |job_id|
    out = workflow.get_job(job_id)

    enqueue_job!(out) if out.ready_to_start?
  end
end

#fail_job!(job) ⇒ Object



66
67
68
69
# File 'lib/burst/manager.rb', line 66

def fail_job!(job)
  job.fail!
  job.save!
end

#finish_job!(job) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/burst/manager.rb', line 49

def finish_job!(job)
  job.finish!
  job.save!

  workflow.with_lock do
    enqueue_outgoing_jobs(job)
  end
end

#job_performed!(job, result) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/burst/manager.rb', line 58

def job_performed!(job, result)
  if result == Burst::Job::SUSPEND || job.output == Burst::Job::SUSPEND
    suspend_job!(job)
  else
    finish_job!(job)
  end
end

#resume!(job, data) ⇒ Object



26
27
28
29
30
31
# File 'lib/burst/manager.rb', line 26

def resume!(job, data)
  job.resume!
  job.save! do
    Burst::Worker.perform_later(workflow.id, job.id, data)
  end
end

#resume_job!(job, data) ⇒ Object



40
41
42
# File 'lib/burst/manager.rb', line 40

def resume_job!(job, data)
  job.resume(data)
end

#startObject



9
10
11
12
13
14
15
16
17
# File 'lib/burst/manager.rb', line 9

def start
  workflow.with_lock do
    raise 'Already started' unless workflow.initial?

    workflow.initial_jobs.each do |job|
      enqueue_job!(job)
    end
  end
end

#start_job!(job) ⇒ Object



33
34
35
36
37
38
# File 'lib/burst/manager.rb', line 33

def start_job!(job)
  job.start!
  job.save!

  job.perform
end

#suspend_job!(job) ⇒ Object



44
45
46
47
# File 'lib/burst/manager.rb', line 44

def suspend_job!(job)
  job.suspend!
  job.save!
end