Skip to content

Commit 1d29fa2

Browse files
committed
Add ability to configure a worker_queue
This works by overriding the `perform_async` method. I was surprised this works, but it does.
1 parent d4fec14 commit 1d29fa2

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lib/fabric.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class Config
146146
attr_accessor :worker_callback
147147
attr_accessor :persist_models
148148
attr_accessor :currencies
149+
attr_accessor :worker_queue
149150

150151
def initialize
151152
@store_events = true
@@ -154,6 +155,7 @@ def initialize
154155
@worker_callback = Proc.new {}
155156
@persist_models = :all
156157
@currencies = %w(usd)
158+
@worker_queue = 'fabric'
157159
end
158160

159161
def persist?(document)

lib/fabric/app/workers/webhook_worker.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ module Fabric
22
class WebhookWorker
33
include Sidekiq::Worker
44

5-
sidekiq_options queue: 'fabric'
5+
def self.perform_async(...)
6+
set(queue: Fabric.config.worker_queue).perform_async(...)
7+
end
68

79
def perform(event, webhook_class)
810
log_data = { event: event['id'], webhook_class: webhook_class }

lib/fabric/app/workers/worker.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ class Worker
33
include Fabric
44
include Sidekiq::Worker
55

6-
sidekiq_options queue: 'fabric', retry: false
6+
sidekiq_options retry: false
7+
8+
def self.perform_async(...)
9+
set(queue: Fabric.config.worker_queue).perform_async(...)
10+
end
711

812
def perform(operation, *args)
913
@log_data = { class: self.class.name, operation: operation, args: args }

0 commit comments

Comments
 (0)