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(opts = {}) ⇒ Job

Returns a new instance of Job.



7
8
9
10
# File 'lib/gush/job.rb', line 7

def initialize(opts = {})
  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

#idObject (readonly)

Returns the value of attribute id.



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

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

#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

#queueObject

Returns the value of attribute queue.



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

def queue
  @queue
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(hash) ⇒ Object



37
38
39
# File 'lib/gush/job.rb', line 37

def self.from_hash(hash)
  hash[:klass].constantize.new(hash)
end

Instance Method Details

#as_jsonObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gush/job.rb', line 12

def as_json
  {
    id: id,
    klass: klass.to_s,
    queue: queue,
    incoming: incoming,
    outgoing: outgoing,
    finished_at: finished_at,
    enqueued_at: enqueued_at,
    started_at: started_at,
    failed_at: failed_at,
    params: params,
    workflow_id: workflow_id,
    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

#nameObject



29
30
31
# File 'lib/gush/job.rb', line 29

def name
  @name ||= "#{klass}|#{id}"
end

#output(data) ⇒ Object



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

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.any? do |name|
    !client.find_job(workflow_id, name).succeeded?
  end
end

#performObject



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

def perform
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



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

def start!
  @started_at = current_timestamp
  @failed_at = nil
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



33
34
35
# File 'lib/gush/job.rb', line 33

def to_json(options = {})
  Gush::JSON.encode(as_json)
end