Merge pull request #9309 from demarches-simplifiees/long_migration
Ajout d'un cron pour maintenir le nombre de pjs en cours de migration entre 0 et 200K
This commit is contained in:
commit
97e4cf437a
1 changed files with 26 additions and 0 deletions
26
app/jobs/cron/pjs_migration_cron_job.rb
Normal file
26
app/jobs/cron/pjs_migration_cron_job.rb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
class Cron::PjsMigrationCronJob < Cron::CronJob
|
||||||
|
self.schedule_expression = "every 15 minutes"
|
||||||
|
|
||||||
|
def perform(*args)
|
||||||
|
# avoid reschedule enqueued jobs
|
||||||
|
# but ignore fail jobs
|
||||||
|
return if migration_jobs.count > 100
|
||||||
|
|
||||||
|
blobs = ActiveStorage::Blob
|
||||||
|
.where.not("key LIKE '%/%'")
|
||||||
|
.limit(200_000)
|
||||||
|
|
||||||
|
blobs.in_batches { |batch| batch.ids.each { |id| PjsMigrationJob.perform_later(id) } }
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.schedulable?
|
||||||
|
ENV.fetch("MIGRATE_PJS", "enabled") == "enabled"
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def migration_jobs
|
||||||
|
Delayed::Job
|
||||||
|
.where(queue: 'pj_migration_jobs')
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue