Add scheduled job to sync all accounts every 24 hours (#330)

* Add scheduled job to sync all accounts every 30 minutes

Signed-off-by: Nikhil Badyal <nikhill773384@gmail.com>

* Change job queue from default to scheduled

Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>

* Flatten job into single directory

* Every 30 minutes is a bit much and will trigger Sentry warnings

* Locking and logging improvements

* Add support for extra Sidekiq goodies

---------

Signed-off-by: Nikhil Badyal <nikhill773384@gmail.com>
Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>
Co-authored-by: Nikhil Badyal <nikhill773384@gmail.com>
This commit is contained in:
Juan José Mata
2025-11-20 20:58:14 +01:00
committed by GitHub
parent e50a5792a0
commit d6cbf300c7
4 changed files with 26 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ gem "hotwire_combobox"
# Background Jobs
gem "sidekiq"
gem "sidekiq-cron"
gem "sidekiq-unique-jobs"
# Monitoring
gem "vernier"

View File

@@ -603,6 +603,10 @@ GEM
fugit (~> 1.8, >= 1.11.1)
globalid (>= 1.0.1)
sidekiq (>= 6.5.0)
sidekiq-unique-jobs (8.0.11)
concurrent-ruby (~> 1.0, >= 1.0.5)
sidekiq (>= 7.0.0, < 9.0.0)
thor (>= 1.0, < 3.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
@@ -759,6 +763,7 @@ DEPENDENCIES
sentry-sidekiq
sidekiq
sidekiq-cron
sidekiq-unique-jobs
simplecov
skylight
stackprof

14
app/jobs/sync_all_job.rb Normal file
View File

@@ -0,0 +1,14 @@
class SyncAllJob < ApplicationJob
queue_as :scheduled
sidekiq_options lock: :until_executed, on_conflict: :log
def perform
Rails.logger.info("Starting sync for all families")
Family.find_each do |family|
family.sync_later
rescue => e
Rails.logger.error("Failed to sync family #{family.id}: #{e.message}")
end
Rails.logger.info("Completed sync for all families")
end
end

View File

@@ -18,3 +18,9 @@ run_security_health_checks:
class: "SecurityHealthCheckJob"
queue: "scheduled"
description: "Runs security health checks to detect issues with security data"
sync_all_accounts:
cron: "22 2 * * *" # every 24 hours at 2:22am
class: "SyncAllJob"
queue: "scheduled"
description: "Syncs all accounts for all families"