Class: Gush::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/gush/job.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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
  options = opts.dup
  assign_variables(options)
end

Instance Attribute Details

#enqueued_atObject

Returns the value of attribute enqueued_at.



3
4
5
# File 'lib/gush/job.rb', line 3

def enqueued_at
  @enqueued_at
end

#failed_atObject

Returns the value of attribute failed_at.



3
4
5
# File 'lib/gush/job.rb', line 3

def failed_at
  @failed_at
end

#finished_atObject

Returns the value of attribute finished_at.



3
4
5
# File 'lib/gush/job.rb', line 3

def finished_at
  @finished_at
end

#incomingObject

Returns the value of attribute incoming.



3
4
5
# File 'lib/gush/job.rb', line 3

def incoming
  @incoming
end

#klassObject

Returns the value of attribute klass.



3
4
5
# File 'lib/gush/job.rb', line 3

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/gush/job.rb', line 5

def name
  @name
end

#outgoingObject

Returns the value of attribute outgoing.



3
4
5
# File 'lib/gush/job.rb', line 3

def outgoing
  @outgoing
end

#output_payloadObject (readonly)

Returns the value of attribute output_payload.



5
6
7
# File 'lib/gush/job.rb', line 5

def output_payload
  @output_payload
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/gush/job.rb', line 3

def params
  @params
end

#payloadsObject (readonly)

Returns the value of attribute payloads.



5
6
7
# File 'lib/gush/job.rb', line 5

def payloads
  @payloads
end

#payloads_hashObject

Returns the value of attribute payloads_hash.



3
4
5
# File 'lib/gush/job.rb', line 3

def payloads_hash
  @payloads_hash
end

#started_atObject

Returns the value of attribute started_at.



3
4
5
# File 'lib/gush/job.rb', line 3

def started_at
  @started_at
end

#workflow_idObject

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_jsonObject



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 = current_timestamp
  @started_at = nil
  @finished_at = nil
  @failed_at = nil
end

#enqueued?Boolean

Returns:

  • (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 = current_timestamp
end

#failed?Boolean

Returns:

  • (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 = current_timestamp
end

#finished?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/gush/job.rb', line 72

def finished?
  !finished_at.nil?
end

#has_no_dependencies?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


92
93
94
# File 'lib/gush/job.rb', line 92

def ready_to_start?
  !running? && !enqueued? && !finished? && !failed? && parents_succeeded?
end

#running?Boolean

Returns:

  • (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 = current_timestamp
end

#started?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/gush/job.rb', line 84

def started?
  !started_at.nil?
end

#succeeded?Boolean

Returns:

  • (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(options = {})
  Gush::JSON.encode(as_json)
end

#workObject



46
47
# File 'lib/gush/job.rb', line 46

def work
end