Skip to content

Commit

Permalink
improve: Only load async workers if deps available
Browse files Browse the repository at this point in the history
  • Loading branch information
jylamont committed Feb 24, 2025
1 parent f340488 commit f5b98f5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
6 changes: 6 additions & 0 deletions lib/vero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"unsubscribe_api" => "UnsubscribeAPI"
)
loader.ignore("#{__dir__}/generators")

loader.push_dir("#{__dir__}/vero/workers", namespace: Vero)
loader.ignore("#{__dir__}/vero/workers/resque_worker") unless defined?(Resque)
loader.ignore("#{__dir__}/vero/workers/sidekiq_worker") unless defined?(::Sidekiq)
loader.ignore("#{__dir__}/vero/workers/sucker_punch_worker") unless defined?(SuckerPunch)

loader.setup

require "vero/railtie" if defined?(Rails)
17 changes: 0 additions & 17 deletions lib/vero/sucker_punch_worker.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ class Vero::ResqueWorker
@queue = :vero

def self.perform(api_class, domain, options)
new_options = options.transform_keys(&:to_sym)

api_class.constantize.new(domain, new_options).perform

Vero::App.log(self, "method: #{api_class}, options: #{options.to_json}, response: resque job queued")
Vero::Senders::Base.new.call(api_class, domain, options)
rescue => e
Vero::App.log(self, "method: #{api_class}, options: #{options.to_json}, response: #{e.message}")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class Vero::SidekiqWorker
include ::Sidekiq::Worker

def perform(api_class, domain, options)
api_class.constantize.new(domain, options).perform

Vero::App.log(self, "method: #{api_class}, options: #{options.to_json}, response: sidekiq job queued")
Vero::Senders::Base.new.call(api_class, domain, options)
rescue => e
Vero::App.log(self, "method: #{api_class}, options: #{options.to_json}, response: #{e.message}")
end
end
13 changes: 13 additions & 0 deletions lib/vero/workers/sucker_punch_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require "sucker_punch"

class Vero::SuckerPunchWorker
include SuckerPunch::Job

def perform(api_class, domain, options)
Vero::Senders::Base.new.call(api_class, domain, options)
rescue => e
Vero::App.log(self, "method: #{api_class}, options: #{options.to_json}, response: #{e.message}")
end
end

0 comments on commit f5b98f5

Please sign in to comment.