mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-19 21:05:15 +00:00
* Sources say Charlie Kick is stable. Please god * Some tests + guards + unsub URL fix * Fix lockfile! * bin/rubocop -A * if this does not work I am going to kms * phew
32 lines
890 B
Ruby
32 lines
890 B
Ruby
class WeeklySummaryEmailJob < ApplicationJob
|
|
queue_as :literally_whenever
|
|
|
|
def perform(reference_time = Time.current)
|
|
return unless Flipper.enabled?(:weekly_summary_emails)
|
|
|
|
now_utc = reference_time.utc
|
|
cutoff = now_utc - 3.weeks
|
|
|
|
eligible_users(cutoff).find_each do |user|
|
|
WeeklySummaryUserEmailJob.perform_later(user.id, now_utc.iso8601)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def eligible_users(cutoff)
|
|
users = User.arel_table
|
|
heartbeats = Heartbeat.arel_table
|
|
|
|
recent_activity_exists = Heartbeat.unscoped
|
|
.where(heartbeats[:user_id].eq(users[:id]))
|
|
.where(heartbeats[:deleted_at].eq(nil))
|
|
.where(heartbeats[:time].gteq(cutoff.to_f))
|
|
.arel
|
|
.exists
|
|
|
|
User.subscribed("weekly_summary").where(
|
|
users[:created_at].gteq(cutoff).or(recent_activity_exists)
|
|
).where.not(id: DeletionRequest.active.select(:user_id))
|
|
end
|
|
end
|