Class: Gush::Job
Constant Summary collapse
- RECURSION_LIMIT =
1000
- DEFAULTS =
{ finished: false, enqueued: false, failed: false, running: false }
Instance Attribute Summary collapse
-
#enqueued ⇒ Object
Returns the value of attribute enqueued.
-
#failed ⇒ Object
Returns the value of attribute failed.
-
#failed_at ⇒ Object
Returns the value of attribute failed_at.
-
#finished ⇒ Object
Returns the value of attribute finished.
-
#finished_at ⇒ Object
Returns the value of attribute finished_at.
-
#incoming ⇒ Object
Returns the value of attribute incoming.
-
#jid ⇒ Object
Returns the value of attribute jid.
- #logger ⇒ Object
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#outgoing ⇒ Object
Returns the value of attribute outgoing.
-
#running ⇒ Object
Returns the value of attribute running.
-
#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
- #after_work ⇒ Object
- #as_json ⇒ Object
- #before_work ⇒ Object
- #can_be_started?(flow) ⇒ Boolean
- #dependencies(flow, level = 0) ⇒ Object
- #enqueue! ⇒ Object
- #enqueued? ⇒ Boolean
- #fail! ⇒ Object
- #failed? ⇒ Boolean
- #finish! ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(opts = {}) ⇒ Job
constructor
A new instance of Job.
- #running? ⇒ Boolean
- #start! ⇒ Object
- #succeeded? ⇒ Boolean
- #to_json(options = {}) ⇒ Object
- #work ⇒ Object
Methods included from Metadata
Constructor Details
Instance Attribute Details
#enqueued ⇒ Object
Returns the value of attribute enqueued.
16 17 18 |
# File 'lib/gush/job.rb', line 16 def enqueued @enqueued end |
#failed ⇒ Object
Returns the value of attribute failed.
16 17 18 |
# File 'lib/gush/job.rb', line 16 def failed @failed end |
#failed_at ⇒ Object
Returns the value of attribute failed_at.
16 17 18 |
# File 'lib/gush/job.rb', line 16 def failed_at @failed_at end |
#finished ⇒ Object
Returns the value of attribute finished.
16 17 18 |
# File 'lib/gush/job.rb', line 16 def finished @finished end |
#finished_at ⇒ Object
Returns the value of attribute finished_at.
16 17 18 |
# File 'lib/gush/job.rb', line 16 def finished_at @finished_at end |
#incoming ⇒ Object
Returns the value of attribute incoming.
16 17 18 |
# File 'lib/gush/job.rb', line 16 def incoming @incoming end |
#jid ⇒ Object
Returns the value of attribute jid.
16 17 18 |
# File 'lib/gush/job.rb', line 16 def jid @jid end |
#logger ⇒ Object
137 138 139 140 |
# File 'lib/gush/job.rb', line 137 def logger fail "You cannot log when the job is not running" unless running? @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/gush/job.rb', line 19 def name @name end |
#outgoing ⇒ Object
Returns the value of attribute outgoing.
16 17 18 |
# File 'lib/gush/job.rb', line 16 def outgoing @outgoing end |
#running ⇒ Object
Returns the value of attribute running.
16 17 18 |
# File 'lib/gush/job.rb', line 16 def running @running end |
#started_at ⇒ Object
Returns the value of attribute started_at.
16 17 18 |
# File 'lib/gush/job.rb', line 16 def started_at @started_at end |
#workflow_id ⇒ Object
Returns the value of attribute workflow_id.
16 17 18 |
# File 'lib/gush/job.rb', line 16 def workflow_id @workflow_id end |
Class Method Details
.from_hash(hash) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gush/job.rb', line 48 def self.from_hash(hash) hash[:klass].constantize.new( name: hash[:name], finished: hash[:finished], enqueued: hash[:enqueued], failed: hash[:failed], incoming: hash[:incoming], outgoing: hash[:outgoing], failed_at: hash[:failed_at], finished_at: hash[:finished_at], started_at: hash[:started_at], running: hash[:running] ) end |
Instance Method Details
#after_work ⇒ Object
69 70 |
# File 'lib/gush/job.rb', line 69 def after_work end |
#as_json ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gush/job.rb', line 28 def as_json { name: @name, klass: self.class.to_s, finished: @finished, enqueued: @enqueued, failed: @failed, incoming: @incoming, outgoing: @outgoing, finished_at: @finished_at, started_at: @started_at, failed_at: @failed_at, running: @running } end |
#before_work ⇒ Object
63 64 |
# File 'lib/gush/job.rb', line 63 def before_work end |
#can_be_started?(flow) ⇒ Boolean
124 125 126 127 128 129 130 |
# File 'lib/gush/job.rb', line 124 def can_be_started?(flow) !running? && !enqueued? && !finished? && !failed? && dependencies_satisfied?(flow) end |
#dependencies(flow, level = 0) ⇒ Object
132 133 134 135 |
# File 'lib/gush/job.rb', line 132 def dependencies(flow, level = 0) fail DependencyLevelTooDeep if level > RECURSION_LIMIT (incoming.map {|name| flow.find_job(name) } + incoming.flat_map{ |name| flow.find_job(name).dependencies(flow, level + 1) }).uniq end |
#enqueue! ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/gush/job.rb', line 78 def enqueue! @enqueued = true @running = false @failed = false @started_at = nil @finished_at = nil @failed_at = nil end |
#enqueued? ⇒ Boolean
104 105 106 |
# File 'lib/gush/job.rb', line 104 def enqueued? !!enqueued end |
#fail! ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/gush/job.rb', line 95 def fail! @finished = true @running = false @failed = true @enqueued = false @finished_at = Time.now.to_i @failed_at = Time.now.to_i end |
#failed? ⇒ Boolean
112 113 114 |
# File 'lib/gush/job.rb', line 112 def failed? !!failed end |
#finish! ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/gush/job.rb', line 87 def finish! @running = false @finished = true @enqueued = false @failed = false @finished_at = Time.now.to_i end |
#finished? ⇒ Boolean
108 109 110 |
# File 'lib/gush/job.rb', line 108 def finished? !!finished end |
#running? ⇒ Boolean
120 121 122 |
# File 'lib/gush/job.rb', line 120 def running? !!running end |
#start! ⇒ Object
72 73 74 75 76 |
# File 'lib/gush/job.rb', line 72 def start! @enqueued = false @running = true @started_at = Time.now.to_i end |
#succeeded? ⇒ Boolean
116 117 118 |
# File 'lib/gush/job.rb', line 116 def succeeded? finished? && !failed? end |
#to_json(options = {}) ⇒ Object
44 45 46 |
# File 'lib/gush/job.rb', line 44 def to_json( = {}) Yajl::Encoder.new.encode(as_json) end |
#work ⇒ Object
66 67 |
# File 'lib/gush/job.rb', line 66 def work end |