Skip to content

Commit

Permalink
Allow setting queue for each job (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
devilankur18 authored and pokonski committed Aug 24, 2018
1 parent 3d906fe commit 5e14330
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/gush/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ def expire_job(workflow_id, job, ttl=nil)
def enqueue_job(workflow_id, job)
job.enqueue!
persist_job(workflow_id, job)
queue = job.queue || configuration.namespace

Gush::Worker.set(queue: configuration.namespace).perform_later(*[workflow_id, job.name])
Gush::Worker.set(queue: queue).perform_later(*[workflow_id, job.name])
end

private
Expand Down
4 changes: 3 additions & 1 deletion lib/gush/job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Gush
class Job
attr_accessor :workflow_id, :incoming, :outgoing, :params,
:finished_at, :failed_at, :started_at, :enqueued_at, :payloads, :klass
:finished_at, :failed_at, :started_at, :enqueued_at, :payloads, :klass, :queue
attr_reader :id, :klass, :output_payload, :params

def initialize(opts = {})
Expand All @@ -13,6 +13,7 @@ def as_json
{
id: id,
klass: klass.to_s,
queue: queue,
incoming: incoming,
outgoing: outgoing,
finished_at: finished_at,
Expand Down Expand Up @@ -123,6 +124,7 @@ def assign_variables(opts)
@klass = opts[:klass] || self.class
@output_payload = opts[:output_payload]
@workflow_id = opts[:workflow_id]
@queue = opts[:queue]
end
end
end
3 changes: 2 additions & 1 deletion lib/gush/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def run(klass, opts = {})
node = klass.new({
workflow_id: id,
id: client.next_free_job_id(id, klass.to_s),
params: opts.fetch(:params, {})
params: opts.fetch(:params, {}),
queue: opts[:queue]
})

jobs << node
Expand Down
1 change: 1 addition & 0 deletions spec/gush/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
finished_at: 123,
enqueued_at: 120,
params: {},
queue: nil,
output_payload: nil,
workflow_id: 123
}
Expand Down

0 comments on commit 5e14330

Please sign in to comment.