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

#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

Returns the value of attribute payloads


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

def payloads
  @payloads
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


47
48
49
50
51
52
# File 'lib/gush/job.rb', line 47

def enqueue!
  @enqueued_at = current_timestamp
  @started_at = nil
  @finished_at = nil
  @failed_at = nil
end

#enqueued?Boolean

Returns:

  • (Boolean)

62
63
64
# File 'lib/gush/job.rb', line 62

def enqueued?
  !enqueued_at.nil?
end

#fail!Object


58
59
60
# File 'lib/gush/job.rb', line 58

def fail!
  @finished_at = @failed_at = current_timestamp
end

#failed?Boolean

Returns:

  • (Boolean)

70
71
72
# File 'lib/gush/job.rb', line 70

def failed?
  !failed_at.nil?
end

#finish!Object


54
55
56
# File 'lib/gush/job.rb', line 54

def finish!
  @finished_at = current_timestamp
end

#finished?Boolean

Returns:

  • (Boolean)

66
67
68
# File 'lib/gush/job.rb', line 66

def finished?
  !finished_at.nil?
end

#has_no_dependencies?Boolean

Returns:

  • (Boolean)

96
97
98
# File 'lib/gush/job.rb', line 96

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)

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

def parents_succeeded?
  incoming.all? do |name|
    @workflow.find_job(name).succeeded?
  end
end

#ready_to_start?Boolean

Returns:

  • (Boolean)

86
87
88
# File 'lib/gush/job.rb', line 86

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

#running?Boolean

Returns:

  • (Boolean)

82
83
84
# File 'lib/gush/job.rb', line 82

def running?
  started? && !finished?
end

#start!Object


43
44
45
# File 'lib/gush/job.rb', line 43

def start!
  @started_at = current_timestamp
end

#started?Boolean

Returns:

  • (Boolean)

78
79
80
# File 'lib/gush/job.rb', line 78

def started?
  !started_at.nil?
end

#succeeded?Boolean

Returns:

  • (Boolean)

74
75
76
# File 'lib/gush/job.rb', line 74

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


40
41
# File 'lib/gush/job.rb', line 40

def work
end