Class: Burstflow::Job

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Rescuable, Callbacks, Initialization, Model, State
Defined in:
lib/burstflow/job.rb

Defined Under Namespace

Modules: Callbacks, Initialization, Model, State Classes: InternalError

Constant Summary collapse

SUSPEND =
'suspend'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#payloadsObject

Returns the value of attribute payloads.



17
18
19
# File 'lib/burstflow/job.rb', line 17

def payloads
  @payloads
end

#workflowObject

Returns the value of attribute workflow.



17
18
19
# File 'lib/burstflow/job.rb', line 17

def workflow
  @workflow
end

Instance Method Details

#attributesObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/burstflow/job.rb', line 79

def attributes
  {
    workflow_id: self.workflow_id,
    id: self.id,
    klass: self.klass,
    params: params,
    incoming: self.incoming,
    outgoing: self.outgoing,
    output: output,
    started_at: started_at,
    enqueued_at: enqueued_at,
    finished_at: finished_at,
    failed_at: failed_at,
    suspended_at: suspended_at,
    resumed_at: resumed_at,
    failure: self.failure
  }
end

#configure(*args, &block) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/burstflow/job.rb', line 69

def configure *args, &block
  workflow.with_lock do

    builder = Burstflow::Workflow::Builder.new(workflow, *args, &block)
    workflow.flow['jobs_config'] = builder.as_json
    workflow.save!
    reload
  end
end

#performObject

execute this code by ActiveJob. You may return Burstflow::Job::SUSPEND to suspend job, or call suspend method



33
34
# File 'lib/burstflow/job.rb', line 33

def perform
end

#perform_nowObject



36
37
38
39
40
41
42
# File 'lib/burstflow/job.rb', line 36

def perform_now
  run_callbacks :perform do
    perform
  end
rescue => exception
  rescue_with_handler(exception) || raise
end

#resume(data) ⇒ Object

execute this code when resumes after suspending

Raises:



45
46
47
48
# File 'lib/burstflow/job.rb', line 45

def resume(data)
  raise InternalError.new(self, "Can't perform resume: not resumed") if !resumed?
  set_output(data)
end

#resume_now(data) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/burstflow/job.rb', line 50

def resume_now data
  run_callbacks :resume do
    resume(data)
  end
rescue => exception
  rescue_with_handler(exception) || raise
end

#save!Object



24
25
26
27
28
29
30
# File 'lib/burstflow/job.rb', line 24

def save!
  workflow.with_lock do
    workflow.set_job(self)
    workflow.save!
    yield if block_given?
  end
end

#set_output(data) ⇒ Object

store data to be available for next jobs



59
60
61
# File 'lib/burstflow/job.rb', line 59

def set_output(data)
  self.output = data
end

#suspendObject

mark execution as suspended

Raises:



64
65
66
67
# File 'lib/burstflow/job.rb', line 64

def suspend
  raise InternalError.new(self, "Can't suspend: not running") if !running?
  set_output(SUSPEND)
end