inter-hub-haskell/Web/Job/QuotaResetJob.hs

19 lines
609 B
Haskell
Raw Normal View History

2026-04-01 19:52:20 +00:00
module Web.Job.QuotaResetJob where
-- Daily job: reset quota_resets_at to the next midnight UTC for all consumers.
-- Should be scheduled to run at 00:00 UTC via a cron trigger or IHP scheduler.
import Generated.Types
import IHP.Prelude
import IHP.ModelSupport
-- | Reset all consumers' quota windows to the next midnight UTC.
-- Call this once per day at 00:00 UTC.
runQuotaReset :: (?modelContext :: ModelContext) => IO ()
runQuotaReset = do
sqlExec
"UPDATE api_consumers \
\SET quota_resets_at = date_trunc('day', NOW() AT TIME ZONE 'UTC') + INTERVAL '1 day'"
()
pure ()