rails-activejob

Efficiently reschedule ActiveJob (resque/sidekiq)

帅比萌擦擦* 提交于 2019-12-09 13:50:03
问题 I'm playing with Rails 4.2 app which uses ActiveJob backed by resque/sidekiq for email scheduling. When a user creates newsletter campaign a new job is created and scheduled on certain date. That's all great but what happens when the user changes the delivery date. In this case every job could check if it should be delivered or not thus invalid jobs would be ignored and only the last one would be executed. This could work but if a user would make 1k edits that would push 1k-1 invalid jobs

ActiveJob deliver_later not sending

会有一股神秘感。 提交于 2019-12-08 19:42:46
问题 I have the following method: UserMailer.comment_alert(@comment, user, type).deliver_later Which oddly shows up with the param deliver_now in the rails log: [ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 5bdf9ed1-53d5-42aa-acb2-7ce54ab284e1) to Sidekiq(mailers) with arguments: "UserMailer", "comment_alert", "deliver_now", gid://xxx/Comment/153, gid://xxx/User/26, "Comment" The job never processes, and I see nothing in the Sidekiq log. There is also no mail delivered, ever. I tried

How to limit the failed job retry counter with ActiveJob and Sidekiq?

£可爱£侵袭症+ 提交于 2019-12-08 14:07:25
I would like to limit the number of retries when a job fails using ActiveJob with Sidekiq as adapter. Using Sidekiq, I can do that: class LessRetryableWorker include Sidekiq::Worker sidekiq_options :retry => 5 def perform(...) end end Sidekiq configuration doesn't provide a global retry config. Each Worker is responsible of setting the retry option. So I guess I have to implement it in ActiveJob side to do it properly. Sidekiq provide a server-level config to handle this case. From Sidekiq ruby-doc: Sidekiq.configure_server do |config| config.server_middleware do |chain| chain.add Middleware:

How to perform a background job now?

拥有回忆 提交于 2019-12-08 04:07:44
问题 I want to execute this on background Product.all.map { |product| product.save } When I save the product will call a callback to create a new record in a table with the costs of products I create a job for this, but if I execute perform_now it is not executed on background and perform_later executes long after. I want to execute this right now but in background. I'm not sure if I can just execute this in a thread too. I am using Delayed Job, here is the job class UpdateProductCostsJob <

How to limit the failed job retry counter with ActiveJob and Sidekiq?

删除回忆录丶 提交于 2019-12-08 03:43:33
问题 I would like to limit the number of retries when a job fails using ActiveJob with Sidekiq as adapter. Using Sidekiq, I can do that: class LessRetryableWorker include Sidekiq::Worker sidekiq_options :retry => 5 def perform(...) end end Sidekiq configuration doesn't provide a global retry config. Each Worker is responsible of setting the retry option. So I guess I have to implement it in ActiveJob side to do it properly. 回答1: Sidekiq provide a server-level config to handle this case. From

Difference between Action Job/Mailer's `deliver_now` and `deliver_later`

本小妞迷上赌 提交于 2019-12-06 17:06:10
问题 The common pattern for interfacing with ActionJob in Rails is to set up a Job with a perform() method that gets called asynchronously via perform_now or perform_later In the special case of Mailers, you can directly call deliver_now or deliver_later since ActionJob is well integrated with ActionMailer . The rails documentation has the following comments - # If you want to send the email now use #deliver_now UserMailer.welcome(@user).deliver_now # If you want to send the email through Active

Execute pending job with ActiveJob in rspec

不问归期 提交于 2019-12-05 10:52:35
问题 I have this code to test ActiveJob and ActionMailer with Rspec I don't know how really execute all enqueued job describe 'whatever' do include ActiveJob::TestHelper after do clear_enqueued_jobs end it 'should email' do expect(enqueued_jobs.size).to eq(1) end end 回答1: Here is how I solved a similar problem: # rails_helper.rb RSpec.configure do |config| config.before :example, perform_enqueued: true do @old_perform_enqueued_jobs = ActiveJob::Base.queue_adapter.perform_enqueued_jobs @old_perform

Should you still pass only the object id when using ActiveJob?

こ雲淡風輕ζ 提交于 2019-12-05 01:12:05
What are the pros and cons of doing the following in ActiveJob: Option A: // Controller MyJob.perform_later(object.id) // my_job.rb def perform(object_id) object = Object.find(object_id) // do stuff end Option B: // Controller MyJob.perform_later(object) // my_job.rb def perform(object) // do stuff end ActiveJob now uses the new Globalid library behind the scenes to serialize/deserialize an ActiveRecord instance, therefore you can now pass an ActiveRecord object. I personally prefer to keep passing the ID as it makes the code more interoperable with other components and it doesn't tie my code

MonkeyPatching ActiveJobs

雨燕双飞 提交于 2019-12-04 13:56:42
I am having an issue monkey-patching part of ActiveJobs. I have the following code in config/initializers/extensions/arguements.rb module ActiveJob module Arguments TYPE_WHITELIST = [ Date, DateTime, Time, NilClass, Fixnum, Float, String, TrueClass, FalseClass, Bignum ] end end Basically, I am trying to add basic support for Date/Time objects for use in the ActiveJob created by ActionMailer#deliver_later Upon loading the rails app I can see my whitelist is loaded, however when I call the deliver_later method on a mailer the original whitelist overrides my patch. #List is correct when app loads

Execute pending job with ActiveJob in rspec

江枫思渺然 提交于 2019-12-04 00:32:44
I have this code to test ActiveJob and ActionMailer with Rspec I don't know how really execute all enqueued job describe 'whatever' do include ActiveJob::TestHelper after do clear_enqueued_jobs end it 'should email' do expect(enqueued_jobs.size).to eq(1) end end timsly Here is how I solved a similar problem: # rails_helper.rb RSpec.configure do |config| config.before :example, perform_enqueued: true do @old_perform_enqueued_jobs = ActiveJob::Base.queue_adapter.perform_enqueued_jobs @old_perform_enqueued_at_jobs = ActiveJob::Base.queue_adapter.perform_enqueued_at_jobs ActiveJob::Base.queue