mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 11:47:56 +01:00
Fix sidekiq cron SendRecapEmails job scheduling creation (#442)
This commit is contained in:
committed by
GitHub
parent
9b57df60a4
commit
87b267998b
@@ -32,7 +32,7 @@ class InvitationsController < ApplicationController
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
InvitationMailer.invite(invitation: invitation, subject: subject, body: body_with_link).deliver_now
|
InvitationMailer.invite(invitation: invitation, subject: subject, body: body_with_link).deliver_later
|
||||||
|
|
||||||
num_invitations_sent += 1
|
num_invitations_sent += 1
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ class SendRecapEmails < ActiveJob::Base
|
|||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
# Fix times to 15:00 UTC
|
# Fix times to 15:00 UTC
|
||||||
time_now = Time.now.utc.change(hour: args[0], min: 0, sec: 0)
|
hour = 15
|
||||||
one_day_ago = 1.day.ago.utc.change(hour: args[0], min: 0, sec: 0)
|
time_now = Time.now.utc.change(hour: hour, min: 0, sec: 0)
|
||||||
one_week_ago = 1.week.ago.utc.change(hour: args[0], min: 0, sec: 0)
|
one_day_ago = 1.day.ago.utc.change(hour: hour, min: 0, sec: 0)
|
||||||
one_month_ago = 1.month.ago.utc.change(hour: args[0], min: 0, sec: 0)
|
one_week_ago = 1.week.ago.utc.change(hour: hour, min: 0, sec: 0)
|
||||||
|
one_month_ago = 1.month.ago.utc.change(hour: hour, min: 0, sec: 0)
|
||||||
|
|
||||||
# Get tenants with active subscriptions
|
# Get tenants with active subscriptions
|
||||||
tbs = TenantBilling.unscoped.all
|
tbs = TenantBilling.unscoped.all
|
||||||
|
|||||||
@@ -77,7 +77,9 @@
|
|||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<p>You have to <a href="https://docs.astuto.io/deploy-with-sidekiq">enable Sidekiq</a> to receive recap notifications.</p>
|
<% if not Rails.application.multi_tenancy? %>
|
||||||
|
<p>You have to <a href="https://docs.astuto.io/deploy-with-sidekiq">enable Sidekiq</a> to receive recap notifications.</p>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
if ENV["ACTIVE_JOB_BACKEND"] == "sidekiq"
|
if ENV['ACTIVE_JOB_BACKEND'] == 'sidekiq'
|
||||||
Sidekiq.configure_server do |config|
|
Sidekiq.configure_server do |config|
|
||||||
redis_url = ENV["REDIS_URL"].dup
|
redis_url = ENV['REDIS_URL'].dup
|
||||||
redis_url.insert(8, ":#{ENV['REDIS_PASSWORD']}@")
|
redis_url.insert(8, ":#{ENV['REDIS_PASSWORD']}@")
|
||||||
|
|
||||||
config.logger.level = Rails.env.production? ? Logger::INFO : Logger::DEBUG
|
config.logger.level = Rails.env.production? ? Logger::INFO : Logger::DEBUG
|
||||||
@@ -8,10 +8,33 @@ if ENV["ACTIVE_JOB_BACKEND"] == "sidekiq"
|
|||||||
end
|
end
|
||||||
|
|
||||||
Sidekiq.configure_client do |config|
|
Sidekiq.configure_client do |config|
|
||||||
redis_url = ENV["REDIS_URL"].dup
|
redis_url = ENV['REDIS_URL'].dup
|
||||||
redis_url.insert(8, ":#{ENV['REDIS_PASSWORD']}@")
|
redis_url.insert(8, ":#{ENV['REDIS_PASSWORD']}@")
|
||||||
|
|
||||||
config.logger.level = Rails.env.production? ? Logger::INFO : Logger::DEBUG
|
config.logger.level = Rails.env.production? ? Logger::INFO : Logger::DEBUG
|
||||||
config.redis = { url: redis_url }
|
config.redis = { url: redis_url }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 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_poll_interval = Rails.env.production? ? 30 : 15
|
||||||
|
config.cron_history_size = 50
|
||||||
|
config.default_namespace = 'default'
|
||||||
|
config.natural_cron_parsing_mode = :strict
|
||||||
|
|
||||||
|
# Handles the case when the Sidekiq process was down for a while and the cron job should have run (set to 10 minutes, i.e. 600 seconds)
|
||||||
|
# This could happen during the deployment of a new version of the application
|
||||||
|
config.reschedule_grace_period = 600
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
Sidekiq::Cron.configure do |config|
|
|
||||||
config.cron_schedule_file = 'config/sidekiq_cron_schedule.yml'
|
|
||||||
|
|
||||||
config.cron_poll_interval = 30
|
|
||||||
config.cron_history_size = 50
|
|
||||||
config.default_namespace = 'default'
|
|
||||||
config.natural_cron_parsing_mode = :strict
|
|
||||||
|
|
||||||
# Handles the case when the Sidekiq process was down for a while and the cron job should have run (set to 10 minutes, i.e. 600 seconds)
|
|
||||||
# This could happen during the deployment of a new version of the application
|
|
||||||
config.reschedule_grace_period = 600
|
|
||||||
end
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# For crontab syntax, see https://crontab.guru/
|
|
||||||
|
|
||||||
send_recap_emails:
|
|
||||||
cron: "0 15 * * *" # At 15:00 every day
|
|
||||||
# cron: "*/30 * * * * *" # Execute every 30 seconds (for testing purposes)
|
|
||||||
class: "SendRecapEmails"
|
|
||||||
queue: default
|
|
||||||
args:
|
|
||||||
hour: 15 # This should be in sync with the "cron" time
|
|
||||||
Reference in New Issue
Block a user