Class: Gush::Job
- Inherits:
-
Object
- Object
- Gush::Job
- Defined in:
- lib/gush/job.rb
Instance Attribute Summary collapse
-
#enqueued_at ⇒ Object
Returns the value of attribute enqueued_at.
-
#failed_at ⇒ Object
Returns the value of attribute failed_at.
-
#finished_at ⇒ Object
Returns the value of attribute finished_at.
-
#incoming ⇒ Object
Returns the value of attribute incoming.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#outgoing ⇒ Object
Returns the value of attribute outgoing.
-
#output_payload ⇒ Object
readonly
Returns the value of attribute output_payload.
-
#params ⇒ Object
Returns the value of attribute params.
-
#payloads ⇒ Object
readonly
Returns the value of attribute payloads.
-
#payloads_hash ⇒ Object
Returns the value of attribute payloads_hash.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
-
#workflow_id ⇒ Object
Returns the value of attribute workflow_id.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #enqueue! ⇒ Object
- #enqueued? ⇒ Boolean
- #fail! ⇒ Object
- #failed? ⇒ Boolean
- #finish! ⇒ Object
- #finished? ⇒ Boolean
- #has_no_dependencies? ⇒ Boolean
-
#initialize(workflow, opts = {}) ⇒ Job
constructor
A new instance of Job.
- #output(data) ⇒ Object
- #parents_succeeded? ⇒ Boolean
- #ready_to_start? ⇒ Boolean
- #running? ⇒ Boolean
- #start! ⇒ Object
- #started? ⇒ Boolean
- #succeeded? ⇒ Boolean
- #to_json(options = {}) ⇒ Object
- #work ⇒ Object
Constructor Details
#initialize(workflow, opts = {}) ⇒ Job
Returns a new instance of Job.
7 8 9 10 11 |
# File 'lib/gush/job.rb', line 7 def initialize(workflow, opts = {}) @workflow = workflow = opts.dup assign_variables() end |
Instance Attribute Details
#enqueued_at ⇒ Object
Returns the value of attribute enqueued_at.
3 4 5 |
# File 'lib/gush/job.rb', line 3 def enqueued_at @enqueued_at end |
#failed_at ⇒ Object
Returns the value of attribute failed_at.
3 4 5 |
# File 'lib/gush/job.rb', line 3 def failed_at @failed_at end |
#finished_at ⇒ Object
Returns the value of attribute finished_at.
3 4 5 |
# File 'lib/gush/job.rb', line 3 def finished_at @finished_at end |
#incoming ⇒ Object
Returns the value of attribute incoming.
3 4 5 |
# File 'lib/gush/job.rb', line 3 def incoming @incoming end |
#klass ⇒ Object
Returns the value of attribute klass.
3 4 5 |
# File 'lib/gush/job.rb', line 3 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/gush/job.rb', line 5 def name @name end |
#outgoing ⇒ Object
Returns the value of attribute outgoing.
3 4 5 |
# File 'lib/gush/job.rb', line 3 def outgoing @outgoing end |
#output_payload ⇒ Object (readonly)
Returns the value of attribute output_payload.
5 6 7 |
# File 'lib/gush/job.rb', line 5 def output_payload @output_payload end |
#params ⇒ Object
Returns the value of attribute params.
3 4 5 |
# File 'lib/gush/job.rb', line 3 def params @params end |
#payloads ⇒ Object (readonly)
Returns the value of attribute payloads.
5 6 7 |
# File 'lib/gush/job.rb', line 5 def payloads @payloads end |
#payloads_hash ⇒ Object
Returns the value of attribute payloads_hash.
3 4 5 |
# File 'lib/gush/job.rb', line 3 def payloads_hash @payloads_hash end |
#started_at ⇒ Object
Returns the value of attribute started_at.
3 4 5 |
# File 'lib/gush/job.rb', line 3 def started_at @started_at end |
#workflow_id ⇒ Object
Returns the value of attribute workflow_id.
3 4 5 |
# File 'lib/gush/job.rb', line 3 def workflow_id @workflow_id end |
Class Method Details
.from_hash(flow, hash) ⇒ Object
32 33 34 |
# File 'lib/gush/job.rb', line 32 def self.from_hash(flow, hash) hash[:klass].constantize.new(flow, hash) end |
Instance Method Details
#as_json ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gush/job.rb', line 13 def as_json { name: name, klass: self.class.to_s, incoming: incoming, outgoing: outgoing, finished_at: finished_at, enqueued_at: enqueued_at, started_at: started_at, failed_at: failed_at, params: params, output_payload: output_payload } end |
#enqueue! ⇒ Object
53 54 55 56 57 58 |
# File 'lib/gush/job.rb', line 53 def enqueue! @enqueued_at = @started_at = nil @finished_at = nil @failed_at = nil end |
#enqueued? ⇒ Boolean
68 69 70 |
# File 'lib/gush/job.rb', line 68 def enqueued? !enqueued_at.nil? end |
#fail! ⇒ Object
64 65 66 |
# File 'lib/gush/job.rb', line 64 def fail! @finished_at = @failed_at = end |
#failed? ⇒ Boolean
76 77 78 |
# File 'lib/gush/job.rb', line 76 def failed? !failed_at.nil? end |
#finish! ⇒ Object
60 61 62 |
# File 'lib/gush/job.rb', line 60 def finish! @finished_at = end |
#finished? ⇒ Boolean
72 73 74 |
# File 'lib/gush/job.rb', line 72 def finished? !finished_at.nil? end |
#has_no_dependencies? ⇒ Boolean
102 103 104 |
# File 'lib/gush/job.rb', line 102 def has_no_dependencies? incoming.empty? end |
#output(data) ⇒ Object
36 37 38 |
# File 'lib/gush/job.rb', line 36 def output(data) @output_payload = data end |
#parents_succeeded? ⇒ Boolean
96 97 98 99 100 |
# File 'lib/gush/job.rb', line 96 def parents_succeeded? incoming.all? do |name| @workflow.find_job(name).succeeded? end end |
#ready_to_start? ⇒ Boolean
92 93 94 |
# File 'lib/gush/job.rb', line 92 def ready_to_start? !running? && !enqueued? && !finished? && !failed? && parents_succeeded? end |
#running? ⇒ Boolean
88 89 90 |
# File 'lib/gush/job.rb', line 88 def running? started? && !finished? end |
#start! ⇒ Object
49 50 51 |
# File 'lib/gush/job.rb', line 49 def start! @started_at = end |
#started? ⇒ Boolean
84 85 86 |
# File 'lib/gush/job.rb', line 84 def started? !started_at.nil? end |
#succeeded? ⇒ Boolean
80 81 82 |
# File 'lib/gush/job.rb', line 80 def succeeded? finished? && !failed? end |
#to_json(options = {}) ⇒ Object
28 29 30 |
# File 'lib/gush/job.rb', line 28 def to_json( = {}) Gush::JSON.encode(as_json) end |
#work ⇒ Object
46 47 |
# File 'lib/gush/job.rb', line 46 def work end |