Merge pull request #4980 from tchak/human-readable-cron
Use human readable expressions instead of cron gibberish
This commit is contained in:
commit
d9015c4e3c
19 changed files with 39 additions and 16 deletions
1
Gemfile
1
Gemfile
|
@ -28,6 +28,7 @@ gem 'dotenv-rails', require: 'dotenv/rails-now' # dotenv should always be loaded
|
||||||
gem 'flipper'
|
gem 'flipper'
|
||||||
gem 'flipper-active_record'
|
gem 'flipper-active_record'
|
||||||
gem 'flipper-ui'
|
gem 'flipper-ui'
|
||||||
|
gem 'fugit'
|
||||||
gem 'geocoder'
|
gem 'geocoder'
|
||||||
gem 'gon'
|
gem 'gon'
|
||||||
gem 'graphiql-rails'
|
gem 'graphiql-rails'
|
||||||
|
|
|
@ -203,6 +203,8 @@ GEM
|
||||||
http_parser.rb (~> 0.6.0)
|
http_parser.rb (~> 0.6.0)
|
||||||
erubi (1.9.0)
|
erubi (1.9.0)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
|
et-orbi (1.2.4)
|
||||||
|
tzinfo
|
||||||
ethon (0.11.0)
|
ethon (0.11.0)
|
||||||
ffi (>= 1.3.0)
|
ffi (>= 1.3.0)
|
||||||
eventmachine (1.2.7)
|
eventmachine (1.2.7)
|
||||||
|
@ -235,6 +237,9 @@ GEM
|
||||||
fog-json (>= 1.0)
|
fog-json (>= 1.0)
|
||||||
ipaddress (>= 0.8)
|
ipaddress (>= 0.8)
|
||||||
formatador (0.2.5)
|
formatador (0.2.5)
|
||||||
|
fugit (1.3.3)
|
||||||
|
et-orbi (~> 1.1, >= 1.1.8)
|
||||||
|
raabro (~> 1.1)
|
||||||
geocoder (1.6.0)
|
geocoder (1.6.0)
|
||||||
globalid (0.4.2)
|
globalid (0.4.2)
|
||||||
activesupport (>= 4.2.0)
|
activesupport (>= 4.2.0)
|
||||||
|
@ -452,6 +457,7 @@ GEM
|
||||||
puma (3.12.4)
|
puma (3.12.4)
|
||||||
pundit (2.0.1)
|
pundit (2.0.1)
|
||||||
activesupport (>= 3.0.0)
|
activesupport (>= 3.0.0)
|
||||||
|
raabro (1.1.6)
|
||||||
rack (2.2.2)
|
rack (2.2.2)
|
||||||
rack-attack (6.0.0)
|
rack-attack (6.0.0)
|
||||||
rack (>= 1.0, < 3)
|
rack (>= 1.0, < 3)
|
||||||
|
@ -746,6 +752,7 @@ DEPENDENCIES
|
||||||
flipper
|
flipper
|
||||||
flipper-active_record
|
flipper-active_record
|
||||||
flipper-ui
|
flipper-ui
|
||||||
|
fugit
|
||||||
geocoder
|
geocoder
|
||||||
gon
|
gon
|
||||||
graphiql-rails
|
graphiql-rails
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class AdministrateurActivateBeforeExpirationJob < CronJob
|
class AdministrateurActivateBeforeExpirationJob < CronJob
|
||||||
self.cron_expression = "0 8 * * *"
|
self.schedule_expression = "every day at 8 am"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
Administrateur
|
Administrateur
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class AutoArchiveProcedureJob < CronJob
|
class AutoArchiveProcedureJob < CronJob
|
||||||
self.cron_expression = "* * * * *"
|
self.schedule_expression = "every 1 minute"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
Procedure.publiees.where("auto_archive_on <= ?", Time.zone.today).each do |procedure|
|
Procedure.publiees.where("auto_archive_on <= ?", Time.zone.today).each do |procedure|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class CronJob < ApplicationJob
|
class CronJob < ApplicationJob
|
||||||
queue_as :cron
|
queue_as :cron
|
||||||
class_attribute :cron_expression
|
class_attribute :schedule_expression
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def schedule
|
def schedule
|
||||||
|
@ -12,6 +12,10 @@ class CronJob < ApplicationJob
|
||||||
delayed_job.destroy if scheduled?
|
delayed_job.destroy if scheduled?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def display_schedule
|
||||||
|
pp "#{name}: #{schedule_expression} cron(#{cron_expression})"
|
||||||
|
end
|
||||||
|
|
||||||
def scheduled?
|
def scheduled?
|
||||||
delayed_job.present?
|
delayed_job.present?
|
||||||
end
|
end
|
||||||
|
@ -25,5 +29,9 @@ class CronJob < ApplicationJob
|
||||||
.where('handler LIKE ?', "%job_class: #{name}%")
|
.where('handler LIKE ?', "%job_class: #{name}%")
|
||||||
.first
|
.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cron_expression
|
||||||
|
Fugit.do_parse(schedule_expression, multi: :fail).to_cron_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class DeclarativeProceduresJob < CronJob
|
class DeclarativeProceduresJob < CronJob
|
||||||
self.cron_expression = "* * * * *"
|
self.schedule_expression = "every 1 minute"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
Procedure.declarative.find_each(&:process_dossiers!)
|
Procedure.declarative.find_each(&:process_dossiers!)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class DiscardedDossiersDeletionJob < CronJob
|
class DiscardedDossiersDeletionJob < CronJob
|
||||||
self.cron_expression = "0 7 * * *"
|
self.schedule_expression = "every day at 2 am"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
Dossier.discarded_brouillon_expired.destroy_all
|
Dossier.discarded_brouillon_expired.destroy_all
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class DiscardedProceduresDeletionJob < CronJob
|
class DiscardedProceduresDeletionJob < CronJob
|
||||||
self.cron_expression = "0 7 * * *"
|
self.schedule_expression = "every day at 1 am"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
Procedure.discarded_expired.find_each do |procedure|
|
Procedure.discarded_expired.find_each do |procedure|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class ExpiredDossiersDeletionJob < CronJob
|
class ExpiredDossiersDeletionJob < CronJob
|
||||||
self.cron_expression = "0 7 * * *"
|
self.schedule_expression = "every day at 7 am"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
ExpiredDossiersDeletionService.process_expired_dossiers_brouillon
|
ExpiredDossiersDeletionService.process_expired_dossiers_brouillon
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class FindDubiousProceduresJob < CronJob
|
class FindDubiousProceduresJob < CronJob
|
||||||
self.cron_expression = "0 0 * * *"
|
self.schedule_expression = "every day at midnight"
|
||||||
|
|
||||||
FORBIDDEN_KEYWORDS = [
|
FORBIDDEN_KEYWORDS = [
|
||||||
'NIR', 'NIRPP', 'race', 'religion',
|
'NIR', 'NIRPP', 'race', 'religion',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class InstructeurEmailNotificationJob < CronJob
|
class InstructeurEmailNotificationJob < CronJob
|
||||||
self.cron_expression = "0 10 * * MON-FRI"
|
self.schedule_expression = "from monday through friday at 10 am"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
NotificationService.send_instructeur_email_notification
|
NotificationService.send_instructeur_email_notification
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class NotifyDraftNotSubmittedJob < CronJob
|
class NotifyDraftNotSubmittedJob < CronJob
|
||||||
self.cron_expression = "0 7 * * *"
|
self.schedule_expression = "from monday through friday at 7 am"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
Dossier.notify_draft_not_submitted
|
Dossier.notify_draft_not_submitted
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class OperationsSignatureJob < CronJob
|
class OperationsSignatureJob < CronJob
|
||||||
self.cron_expression = "0 6 * * *"
|
self.schedule_expression = "every day at 6 am"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
last_midnight = Time.zone.today.beginning_of_day
|
last_midnight = Time.zone.today.beginning_of_day
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class PurgeStaleExportsJob < CronJob
|
class PurgeStaleExportsJob < CronJob
|
||||||
self.cron_expression = "*/5 * * * *"
|
self.schedule_expression = "every 5 minutes"
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
Export.stale.destroy_all
|
Export.stale.destroy_all
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class PurgeUnattachedBlobsJob < CronJob
|
class PurgeUnattachedBlobsJob < CronJob
|
||||||
self.cron_expression = "0 0 * * *"
|
self.schedule_expression = "every day at midnight"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
ActiveStorage::Blob.unattached
|
ActiveStorage::Blob.unattached
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class UpdateAdministrateurUsageStatisticsJob < CronJob
|
class UpdateAdministrateurUsageStatisticsJob < CronJob
|
||||||
self.cron_expression = "0 10 * * *"
|
self.schedule_expression = "every day at 10 am"
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
AdministrateurUsageStatisticsService.new.update_administrateurs
|
AdministrateurUsageStatisticsService.new.update_administrateurs
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class WarnExpiringDossiersJob < CronJob
|
class WarnExpiringDossiersJob < CronJob
|
||||||
self.cron_expression = "0 0 1 * *"
|
self.schedule_expression = "every 1 month at midnight"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
expiring, expired = Dossier
|
expiring, expired = Dossier
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class WeeklyOverviewJob < CronJob
|
class WeeklyOverviewJob < CronJob
|
||||||
self.cron_expression = "0 7 * * MON"
|
self.schedule_expression = "every monday at 7 am"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
# Feature flipped to avoid mails in staging due to unprocessed dossier
|
# Feature flipped to avoid mails in staging due to unprocessed dossier
|
||||||
|
|
|
@ -5,4 +5,11 @@ namespace :jobs do
|
||||||
Dir.glob(glob).each { |f| require f }
|
Dir.glob(glob).each { |f| require f }
|
||||||
CronJob.subclasses.each(&:schedule)
|
CronJob.subclasses.each(&:schedule)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc 'Display schedule for all cron jobs'
|
||||||
|
task display_schedule: :environment do
|
||||||
|
glob = Rails.root.join('app', 'jobs', '**', '*_job.rb')
|
||||||
|
Dir.glob(glob).each { |f| require f }
|
||||||
|
CronJob.subclasses.each(&:display_schedule)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue