From 17c3e621b90ee7df32aeca850edd6757447ef40d Mon Sep 17 00:00:00 2001 From: Riccardo Graziosi <31478034+riggraz@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:46:33 +0100 Subject: [PATCH] Fix Sidekiq Cron initializer (#443) --- app/jobs/send_recap_emails.rb | 4 ++++ config/initializers/sidekiq.rb | 14 ++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/jobs/send_recap_emails.rb b/app/jobs/send_recap_emails.rb index 40dcc675..07a60e91 100644 --- a/app/jobs/send_recap_emails.rb +++ b/app/jobs/send_recap_emails.rb @@ -2,6 +2,8 @@ class SendRecapEmails < ActiveJob::Base queue_as :default def perform(*args) + logger.info { "Performing SendRecapEmails ActiveJob" } + # Fix times to 15:00 UTC hour = 15 time_now = Time.now.utc.change(hour: hour, min: 0, sec: 0) @@ -49,6 +51,8 @@ class SendRecapEmails < ActiveJob::Base # Notify each user based on their recap notification frequency users.each do |user| + logger.info { "[#{tenant.subdomain}] Sending recap email to #{user.inspect}" } + # Remove from published_posts the posts published by the user published_posts_daily_user = published_posts_daily&.select { |post| post.user_id != user.id } should_send_daily_recap = published_posts_daily_user&.any? || pending_posts_daily&.any? diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index fbf3ed8a..0d92f1b4 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -18,14 +18,12 @@ if ENV['ACTIVE_JOB_BACKEND'] == 'sidekiq' # Sidekiq Cron if ENV['IS_SIDEKIQ'] == 'true' Sidekiq::Cron.configure do |config| - - # config.cron_schedule_file doesn't work for some reason - # so we have to create the cron jobs manually - unless Sidekiq::Cron::Job.find('SendRecapEmails') - cron_expression = '0 15 * * *' # Every day at 15:00 - # cron_expression = '*/30 * * * * *' # Every 30 seconds (for testing) - Sidekiq::Cron::Job.create(name: 'SendRecapEmails Job', cron: cron_expression, class: 'SendRecapEmails') - end + # config.cron_schedule_file doesn't work for some reason so we have to create the cron jobs manually + Sidekiq::Cron::Job.create( + name: 'SendRecapEmails Job', + cron: ENV.fetch('SEND_RECAP_EMAIL_CRON') { '0 15 * * *' }, # defaults to every day at 15:00 + class: 'SendRecapEmails' + ) config.cron_poll_interval = Rails.env.production? ? 30 : 15 config.cron_history_size = 50