From 2833cfdb8140647062094564d538a98928647745 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Thu, 13 Oct 2016 15:46:57 -0500 Subject: [PATCH] Add Resque worker --- lib/spree/chimpy/workers/resque.rb | 16 ++++++++++++++++ lib/spree_chimpy.rb | 2 ++ 2 files changed, 18 insertions(+) create mode 100644 lib/spree/chimpy/workers/resque.rb diff --git a/lib/spree/chimpy/workers/resque.rb b/lib/spree/chimpy/workers/resque.rb new file mode 100644 index 0000000..3786fae --- /dev/null +++ b/lib/spree/chimpy/workers/resque.rb @@ -0,0 +1,16 @@ +module Spree::Chimpy + module Workers + class Resque + delegate :log, to: Spree::Chimpy + + QUEUE = :default + @queue = QUEUE + + def self.perform(payload) + Spree::Chimpy.perform(payload.with_indifferent_access) + rescue Excon::Errors::Timeout, Excon::Errors::SocketError + log "Mailchimp connection timeout reached, closing" + end + end + end +end diff --git a/lib/spree_chimpy.rb b/lib/spree_chimpy.rb index e9ffb40..301c880 100644 --- a/lib/spree_chimpy.rb +++ b/lib/spree_chimpy.rb @@ -107,6 +107,8 @@ def handle_event(event, payload = {}) run_at: Proc.new { 4.minutes.from_now }) when defined?(::Sidekiq) Spree::Chimpy::Workers::Sidekiq.perform_in(4.minutes, payload.except(:object)) + when defined?(::Resque) + ::Resque.enqueue(Spree::Chimpy::Workers::Resque, payload.except(:object)) else perform(payload) end