Fix Sidekiq Cron initializer (#443)

This commit is contained in:
Riccardo Graziosi
2024-11-27 15:46:33 +01:00
committed by GitHub
parent 87b267998b
commit 17c3e621b9
2 changed files with 10 additions and 8 deletions

View File

@@ -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?

View File

@@ -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