mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 01:01:39 -05:00
21 lines
610 B
Ruby
21 lines
610 B
Ruby
|
|
# frozen_string_literal: true
|
||
|
|
|
||
|
|
class Users::Digests::YearEndSchedulingJob < ApplicationJob
|
||
|
|
queue_as :digests
|
||
|
|
|
||
|
|
def perform
|
||
|
|
year = Time.current.year - 1 # Previous year's digest
|
||
|
|
|
||
|
|
::User.active_or_trial.find_each do |user|
|
||
|
|
# Skip if user has no data for the year
|
||
|
|
next unless user.stats.where(year: year).exists?
|
||
|
|
|
||
|
|
# Schedule calculation first
|
||
|
|
Users::Digests::CalculatingJob.perform_later(user.id, year)
|
||
|
|
|
||
|
|
# Schedule email with delay to allow calculation to complete
|
||
|
|
Users::Digests::EmailSendingJob.set(wait: 30.minutes).perform_later(user.id, year)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|