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.



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

def payloads
  @payloads
end

#workflowObject

Returns the value of attribute workflow.



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

def workflow
  @workflow
end

Instance Method Details

#attributesObject



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

def attributes
  {
    workflow_id: workflow_id,
    id: id,
    klass: klass,
    params: params,
    incoming: incoming,
    outgoing: 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: failure
  }
end

#configure(*args, &block) ⇒ Object



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

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



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

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 StandardError => exception
  rescue_with_handler(exception) || raise
end

#resume(data) ⇒ Object

execute this code when resumes after suspending

Raises:



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

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

  set_output(data)
end

#resume_now(data) ⇒ Object



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

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

#save!Object



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

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



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

def set_output(data)
  self.output = data
end

#suspendObject

mark execution as suspended

Raises:



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

def suspend
  raise InternalError.new(self, "Can't suspend: not running") unless running?

  set_output(SUSPEND)
end