diff options
Diffstat (limited to 'lib/cron.rb')
| -rw-r--r-- | lib/cron.rb | 78 | 
1 files changed, 78 insertions, 0 deletions
| diff --git a/lib/cron.rb b/lib/cron.rb new file mode 100644 index 000000000..fe010ffd9 --- /dev/null +++ b/lib/cron.rb @@ -0,0 +1,78 @@ +module Cron +  class << self + +    def every_day_at_3AM +      sync_reflex +    end + +    def every_day_at_4AM +      sync_codifligne +    end + +    def every_hour +      sync_organizations +      sync_users +    end + +    def every_5_minutes +      check_import_operations +      check_ccset_operations +    end + +    private + +    def sync_organizations +      begin +        Organisation.portail_sync +      rescue => e +        Rails.logger.error(e.inspect) +      end +    end + +    def sync_users +      begin +        User.portail_sync +      rescue => e +        Rails.logger.error(e.inspect) +      end +    end + +    def sync_reflex +      begin +        sync = StopAreaReferential.find_by(name: 'Reflex').stop_area_referential_syncs.build +        raise "reflex:sync aborted - There is already an synchronisation in progress" unless sync.valid? +        sync.save +      rescue => e +        Rails.logger.warn(e.message) +      end +    end + +    def sync_codifligne +      begin +        sync = LineReferential.find_by(name: 'CodifLigne').line_referential_syncs.build +        raise "Codifligne:sync aborted - There is already an synchronisation in progress" unless sync.valid? +        sync.save  +      rescue => e +        Rails.logger.warn(e.message) +      end +    end + +    def check_ccset_operations +      begin +        ParentNotifier.new(ComplianceCheckSet).notify_when_finished +        ComplianceCheckSet.abort_old +      rescue => e +        Rails.logger.error(e.inspect) +      end +    end + +    def check_import_operations +      begin +        ParentNotifier.new(Import::Base).notify_when_finished +        Import::Netex.abort_old +      rescue => e +        Rails.logger.error(e.inspect) +      end +    end +  end +end
\ No newline at end of file | 
