Created
April 29, 2016 14:18
-
-
Save kdiogenes/3f514a0ce0f20767dac6e67eb27a7e87 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Sidekiq::Middleware::ActionMailerDynamicUrlOptions | |
| # Get the current Action Mailer default URL options and store them in the | |
| # message to be sent to Sidekiq. | |
| class Client | |
| def call(worker_class, msg, queue, redis_pool) | |
| msg[DYNAMIC_URL_OPTIONS_KEY] = Thread.current[DYNAMIC_URL_OPTIONS_KEY] | |
| yield | |
| end | |
| end | |
| # Pull the message's Action Mailer default URL options out and set the | |
| # current thread to use them. | |
| class Server | |
| def call(worker, msg, queue) | |
| Thread.current[DYNAMIC_URL_OPTIONS_KEY] = msg[DYNAMIC_URL_OPTIONS_KEY].symbolize_keys | |
| yield | |
| end | |
| end | |
| end | |
| Sidekiq.configure_client do |config| | |
| config.client_middleware do |chain| | |
| chain.add Sidekiq::Middleware::ActionMailerDynamicUrlOptions::Client | |
| end | |
| end | |
| Sidekiq.configure_server do |config| | |
| config.client_middleware do |chain| | |
| chain.add Sidekiq::Middleware::ActionMailerDynamicUrlOptions::Client | |
| end | |
| config.server_middleware do |chain| | |
| chain.add Sidekiq::Middleware::ActionMailerDynamicUrlOptions::Server | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment