From 5e1433085873716b59747e3694d33b2fdc8d4dbd Mon Sep 17 00:00:00 2001 From: Ankur Agarwal Date: Fri, 24 Aug 2018 13:32:14 +0530 Subject: [PATCH] Allow setting queue for each job (#58) --- lib/gush/client.rb | 3 ++- lib/gush/job.rb | 4 +++- lib/gush/workflow.rb | 3 ++- spec/gush/job_spec.rb | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/gush/client.rb b/lib/gush/client.rb index 2755756..0b0469c 100644 --- a/lib/gush/client.rb +++ b/lib/gush/client.rb @@ -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 diff --git a/lib/gush/job.rb b/lib/gush/job.rb index 0dfcbdc..a4382c7 100644 --- a/lib/gush/job.rb +++ b/lib/gush/job.rb @@ -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 = {}) @@ -13,6 +13,7 @@ def as_json { id: id, klass: klass.to_s, + queue: queue, incoming: incoming, outgoing: outgoing, finished_at: finished_at, @@ -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 diff --git a/lib/gush/workflow.rb b/lib/gush/workflow.rb index b3dc232..6e8864a 100644 --- a/lib/gush/workflow.rb +++ b/lib/gush/workflow.rb @@ -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 diff --git a/spec/gush/job_spec.rb b/spec/gush/job_spec.rb index 68824b9..9406b2a 100644 --- a/spec/gush/job_spec.rb +++ b/spec/gush/job_spec.rb @@ -73,6 +73,7 @@ finished_at: 123, enqueued_at: 120, params: {}, + queue: nil, output_payload: nil, workflow_id: 123 }