Skip to content

Commit c9f9d92

Browse files
committed
Allow setting queue for each job
1 parent 9c4c87e commit c9f9d92

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

lib/gush/client.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def create_workflow(name)
1818
rescue NameError
1919
raise WorkflowNotFound.new("Workflow with given name doesn't exist")
2020
end
21-
flow
2221
end
2322

2423
def start_workflow(workflow, job_names = [])
@@ -156,8 +155,9 @@ def workflow_report(message)
156155
def enqueue_job(workflow_id, job)
157156
job.enqueue!
158157
persist_job(workflow_id, job)
158+
queue = job.queue || configuration.namespace
159159

160-
Gush::Worker.set(queue: configuration.namespace).perform_later(*[workflow_id, job.name])
160+
Gush::Worker.set(queue: queue).perform_later(*[workflow_id, job.name])
161161
end
162162

163163
private

lib/gush/job.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Gush
22
class Job
33
attr_accessor :workflow_id, :incoming, :outgoing, :params,
4-
:finished_at, :failed_at, :started_at, :enqueued_at, :payloads, :klass
4+
:finished_at, :failed_at, :started_at, :enqueued_at, :payloads, :klass, :queue
55
attr_reader :name, :output_payload, :params
66

77
def initialize(workflow, opts = {})
@@ -10,10 +10,17 @@ def initialize(workflow, opts = {})
1010
assign_variables(options)
1111
end
1212

13+
def payload(clazz)
14+
payload = payloads.detect { |f| f[:class] == clazz.name }
15+
raise "Unable to find payload for #{clazz}, available: #{payloads.collect { |f| f[:class]}}" unless payload
16+
payload[:output]
17+
end
18+
1319
def as_json
1420
{
1521
name: name,
1622
klass: self.class.to_s,
23+
queue: queue,
1724
incoming: incoming,
1825
outgoing: outgoing,
1926
finished_at: finished_at,
@@ -98,6 +105,9 @@ def has_no_dependencies?
98105
end
99106

100107
private
108+
def logger
109+
Rails.logger
110+
end
101111

102112
def current_timestamp
103113
Time.now.to_i
@@ -114,6 +124,7 @@ def assign_variables(opts)
114124
@params = opts[:params] || {}
115125
@klass = opts[:klass]
116126
@output_payload = opts[:output_payload]
127+
@queue = opts[:queue]
117128
end
118129
end
119130
end

lib/gush/workflow.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ def stopped?
104104
def run(klass, opts = {})
105105
node = klass.new(self, {
106106
name: client.next_free_job_id(id,klass.to_s),
107-
params: opts.fetch(:params, {})
107+
params: opts.fetch(:params, {}),
108+
queue: opts[:queue]
108109
})
109110

110111
jobs << node

0 commit comments

Comments
 (0)