File tree Expand file tree Collapse file tree 4 files changed +29
-11
lines changed
Expand file tree Collapse file tree 4 files changed +29
-11
lines changed Original file line number Diff line number Diff line change 9494require 'fabric/webhooks/subscription_deleted'
9595require 'fabric/webhooks/review_opened'
9696require 'fabric/webhooks/review_closed'
97- require 'fabric/app/workers/worker.rb'
98- require 'fabric/app/workers/webhook_worker.rb'
99- require 'fabric/app/models/fabric/base.rb'
97+ require 'fabric/app/workers/base_worker'
98+ require 'fabric/app/workers/worker'
99+ require 'fabric/app/workers/webhook_worker'
100+ require 'fabric/app/models/fabric/base'
100101
101102module Fabric
102103 autoload :BalanceTransaction , 'fabric/app/models/fabric/balance_transaction'
@@ -146,6 +147,7 @@ class Config
146147 attr_accessor :worker_callback
147148 attr_accessor :persist_models
148149 attr_accessor :currencies
150+ attr_accessor :worker_queue
149151
150152 def initialize
151153 @store_events = true
@@ -154,6 +156,7 @@ def initialize
154156 @worker_callback = Proc . new { }
155157 @persist_models = :all
156158 @currencies = %w( usd )
159+ @worker_queue = 'fabric'
157160 end
158161
159162 def persist? ( document )
Original file line number Diff line number Diff line change 1+ module Fabric
2+ class BaseWorker
3+ include Fabric
4+ include Sidekiq ::Worker
5+
6+ def self . perform_async ( ...)
7+ set ( queue : Fabric . config . worker_queue ) . perform_async ( ...)
8+ end
9+
10+ def self . perform_in ( interval , ...)
11+ set ( queue : Fabric . config . worker_queue ) . perform_in ( interval , ...)
12+ end
13+
14+ def self . perform_at ( timestamp , ...)
15+ set ( queue : Fabric . config . worker_queue ) . perform_at ( timestamp , ...)
16+ end
17+
18+ end
19+ end
Original file line number Diff line number Diff line change 11module Fabric
2- class WebhookWorker
3- include Sidekiq ::Worker
4-
5- sidekiq_options queue : 'fabric'
2+ class WebhookWorker < BaseWorker
63
74 def perform ( event , webhook_class )
85 log_data = { event : event [ 'id' ] , webhook_class : webhook_class }
96 Fabric . config . logger . info ( "started #{ log_data . to_json } " )
107 "Fabric::Webhooks::#{ webhook_class . camelcase } " . constantize . new . call ( event )
118 end
9+
1210 end
1311end
Original file line number Diff line number Diff line change 11module Fabric
2- class Worker
3- include Fabric
4- include Sidekiq ::Worker
2+ class Worker < BaseWorker
53
6- sidekiq_options queue : 'fabric' , retry : false
4+ sidekiq_options retry : false
75
86 def perform ( operation , *args )
97 @log_data = { class : self . class . name , operation : operation , args : args }
You can’t perform that action at this time.
0 commit comments