Skip to content

Commit cf891bb

Browse files
committed
improve: Only load async workers if deps available
1 parent bac9ac2 commit cf891bb

5 files changed

Lines changed: 28 additions & 25 deletions

File tree

lib/vero.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
require "rest-client"
66
require "zeitwerk"
77

8+
module Vero
9+
end
10+
811
loader = Zeitwerk::Loader.for_gem
912
loader.inflector.inflect(
1013
"api_context" => "APIContext",
@@ -19,6 +22,12 @@
1922
"unsubscribe_api" => "UnsubscribeAPI"
2023
)
2124
loader.ignore("#{__dir__}/generators")
25+
26+
loader.push_dir("#{__dir__}/vero/workers", namespace: Vero)
27+
loader.ignore("#{__dir__}/vero/workers/resque_worker") unless defined?(Resque)
28+
loader.ignore("#{__dir__}/vero/workers/sidekiq_worker") unless defined?(::Sidekiq)
29+
loader.ignore("#{__dir__}/vero/workers/sucker_punch_worker") unless defined?(SuckerPunch)
30+
2231
loader.setup
2332

2433
require "vero/railtie" if defined?(Rails)

lib/vero/sucker_punch_worker.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ class Vero::ResqueWorker
66
@queue = :vero
77

88
def self.perform(api_class, domain, options)
9-
new_options = options.transform_keys(&:to_sym)
10-
11-
api_class.constantize.new(domain, new_options).perform
12-
13-
Vero::App.log(self, "method: #{api_class}, options: #{options.to_json}, response: resque job queued")
9+
Vero::Senders::Base.new.call(api_class, domain, options)
10+
rescue => e
11+
Vero::App.log(self, "method: #{api_class}, options: #{options.to_json}, response: #{e.message}")
1412
end
1513
end
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class Vero::SidekiqWorker
66
include ::Sidekiq::Worker
77

88
def perform(api_class, domain, options)
9-
api_class.constantize.new(domain, options).perform
10-
11-
Vero::App.log(self, "method: #{api_class}, options: #{options.to_json}, response: sidekiq job queued")
9+
Vero::Senders::Base.new.call(api_class, domain, options)
10+
rescue => e
11+
Vero::App.log(self, "method: #{api_class}, options: #{options.to_json}, response: #{e.message}")
1212
end
1313
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require "sucker_punch"
4+
5+
class Vero::SuckerPunchWorker
6+
include SuckerPunch::Job
7+
8+
def perform(api_class, domain, options)
9+
Vero::Senders::Base.new.call(api_class, domain, options)
10+
rescue => e
11+
Vero::App.log(self, "method: #{api_class}, options: #{options.to_json}, response: #{e.message}")
12+
end
13+
end

0 commit comments

Comments
 (0)