rails-activejob

Efficiently reschedule ActiveJob (resque/sidekiq)

老子叫甜甜 提交于 2019-12-03 19:33:04
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 into queue - not good. I believe that the existing job should be updated or replaced with a new one. As

How to check what is queued in ActiveJob using Rspec

纵饮孤独 提交于 2019-12-03 04:44:18
问题 I'm working on a reset_password method in a Rails API app. When this endpoint is hit, an ActiveJob is queued that will fire off a request to Mandrill (our transactional email client). I'm currently trying to write the tests to ensure that that the ActiveJob is queued correctly when the controller endpoint is hit. def reset_password @user = User.find_by(email: params[:user][:email]) @user.send_reset_password_instructions end The send_reset_password_instructions creates some url's etc before

How to check what is queued in ActiveJob using Rspec

99封情书 提交于 2019-12-02 17:56:16
I'm working on a reset_password method in a Rails API app. When this endpoint is hit, an ActiveJob is queued that will fire off a request to Mandrill (our transactional email client). I'm currently trying to write the tests to ensure that that the ActiveJob is queued correctly when the controller endpoint is hit. def reset_password @user = User.find_by(email: params[:user][:email]) @user.send_reset_password_instructions end The send_reset_password_instructions creates some url's etc before creating the ActiveJob which's code is below: class SendEmailJob < ActiveJob::Base queue_as :default def

Sidekiq Rails 4.2 Use Active Job or Worker? What's the difference

烂漫一生 提交于 2019-12-02 17:40:19
This is my first processing jobs asynchronously I am implementing Sidekiq for background processing in my app. I will use it for reminder emails and in-app notifications. I am confused as to whether I should use Active Job to create a job that sends an email or a Sidekiq Worker to send an email. They seem to do the same thing and Rails 4.2 Active Job seems very new…is it replacing the need for a Sidekiq Worker? Below is the same sending a mailer code using an Active Job job and a Sidekiq Worker. I am using Whenever gem for scheduling. my_mailers.rb class MyMailers < ActionMailer::Base def some

How to test that ActiveJob is enqueued?

落花浮王杯 提交于 2019-12-02 06:50:28
问题 I have a create action that calls an ActiveJob if the record is successfully saved. def create @object = Object.new(importer_params) respond_to do |format| if @object.save MyJob.perform_later( @object.id ) format.html { redirect_to @object, notice: t('.notice') } else format.html { render :new } end end end I want to test that the Job is correctly called in a controller spec. describe "POST #create" do it { expect { post :create, { object: valid_attributes } }.to change(Object, :count).by(1)

List queued tasks with ActiveJob AsyncAdapter

夙愿已清 提交于 2019-12-01 22:03:38
问题 Is there a way I can see how many (maybe even inspect each job?) jobs are there remaining in the queue? 回答1: After some digging into source code here is what I found out: ActiveJob::QueueAdapters::AsyncAdapter uses a Concurrent Ruby thread pool to schedule and execute jobs. When you initialize the adapter in your configuration, you pass executor options , which in turn happen to be arguments to initialize method of Concurrent::ThreadPoolExecutor class. Created instance of Concurrent:

List queued tasks with ActiveJob AsyncAdapter

夙愿已清 提交于 2019-12-01 19:53:36
Is there a way I can see how many (maybe even inspect each job?) jobs are there remaining in the queue? After some digging into source code here is what I found out: ActiveJob::QueueAdapters::AsyncAdapter uses a Concurrent Ruby thread pool to schedule and execute jobs. When you initialize the adapter in your configuration, you pass executor options , which in turn happen to be arguments to initialize method of Concurrent::ThreadPoolExecutor class. Created instance of Concurrent::ThreadPoolExecutor class has such methods, as: queue_length - The number of tasks in the queue awaiting execution.

Rails 4.2 get delayed job id from active job

拟墨画扇 提交于 2019-11-30 18:08:53
Any idea how to get the Delayed::Job id from the ActiveJob enqueuing? When I enqueue a job I get back an instance of ActiveJob::Base with a @job_id , but that job id seems to be internal to ActiveJob. My best guess so far is just to walk down the most recently created jobs: active_job_id = GenerateReportJob.perform_later(self.id).job_id delayed_job = Delayed::Job.order(id: :desc).limit(5).detect do |job| YAML.load(job.handler).job_data['job_id'] == active_job_id end but that seems all kinds of hacky. Kind of surprised ActiveJob isn't returning the ID from Delayed::Job , especially since that

Resque-Scheduler not working with ActiveJob in Rails 4.2

北慕城南 提交于 2019-11-30 15:13:36
问题 Has anyone been able to get scheduled jobs to work in Rails 4.2? I am using resque, and I am attempting to use resque-scheduler to schedule jobs. I have a schedule that get loaded and the scheduler runs, and even looks like it is running the jobs but it doesn't do anything. resque-scheduler: [INFO] 2014-09-16T01:54:25-07:00: Starting resque-scheduler: [INFO] 2014-09-16T01:54:25-07:00: Loading Schedule resque-scheduler: [INFO] 2014-09-16T01:54:25-07:00: Scheduling friends resque-scheduler:

Rails 4.2 get delayed job id from active job

混江龙づ霸主 提交于 2019-11-29 17:26:48
问题 Any idea how to get the Delayed::Job id from the ActiveJob enqueuing? When I enqueue a job I get back an instance of ActiveJob::Base with a @job_id , but that job id seems to be internal to ActiveJob. My best guess so far is just to walk down the most recently created jobs: active_job_id = GenerateReportJob.perform_later(self.id).job_id delayed_job = Delayed::Job.order(id: :desc).limit(5).detect do |job| YAML.load(job.handler).job_data['job_id'] == active_job_id end but that seems all kinds