mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 19:27:52 +01:00
Fix Sidekiq Cron initializer (#443)
This commit is contained in:
committed by
GitHub
parent
87b267998b
commit
17c3e621b9
@@ -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?
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user