I am a little confused as to where "jobs" and "workers" fall in the workflow of background processing. I'm trying to write my first rake tasks that send periodic emails and almost all tutorials are pre-rails 4.2, and so they suggest I create a Sidekiq worker, etc....though now, that Active Job is rolled into Rails 4.2...I think I can just create a Job...am I correct? I am using Redis, Sidekiq, Rails 4.2 and PG. I am using the Whenever gem for scheduling
Here is what I am doing to create these recurring emails:
send_test_job.rb
class SendTestJob < ActiveJob::Base
queue_as :default
rescue_from(StandardError) do |exception|
notify_failed_job_to_manager(exception)
end
# perform(users, project_archives, rakelogs, projects, user_archives)
def perform
@users = User.all
@subject ="Test Email"
if @users.present?
AdminNotifierMailer.hourly_roundup(@users, @projects, @subject).deliver_later
else
end
end
private
def notify_failed_job_to_manager(exception)
AdminNotifierMailer.job_failed(User.find(?), exception).deliver_later
end
end
scheduler.rake
namespace :admin do
desc "sends a test email"
task :send_test => :environment do
puts "sending Test Job"
SendTestJob.perform_later
puts "done"
end
end
config/schedule.rb (for whenever gem)
every 1.minutes do
rake "admin:send_test", :output => {:error => 'error.log', :standard => 'cron.log'}
end
sidekiq.yml (the code hinting color on this is screwy...so this may be an issue)
---
:concurrency: 25
:pidfile: ./tmp/pids/sidekiq.pid
:logfile: ./log/sidekiq.log
:queues:
- default
- [high_priority, 2]
As you can see I have no workers...but that's because I can't really figure out where to put one or if I need one.
Aucun commentaire:
Enregistrer un commentaire