diff options
| author | cedricnjanga | 2018-05-09 06:51:43 -0700 | 
|---|---|---|
| committer | Johan Van Ryseghem | 2018-05-28 16:20:55 +0200 | 
| commit | 547f8a408883a36f91b1335b67bb9c22de7fbca8 (patch) | |
| tree | 3e7babc4474db260c1d997b508a7fba4681f958c | |
| parent | 7f8d45156a9557bb314ada4f6e015d20556302c0 (diff) | |
| download | chouette-core-547f8a408883a36f91b1335b67bb9c22de7fbca8.tar.bz2 | |
Refs #6962 Add Cron class
| -rw-r--r-- | config/schedule.rb | 14 | ||||
| -rw-r--r-- | lib/cron.rb | 50 | 
2 files changed, 56 insertions, 8 deletions
| diff --git a/config/schedule.rb b/config/schedule.rb index 0d2a24f31..e5ab2556d 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -28,25 +28,23 @@ set :NEW_RELIC_LOG, 'stdout'  set :job_template, "/bin/bash -c ':job'"  every :hour do -  rake "organisations:sync" -  rake "users:sync" +  Cron.sync_organizations +  Cron.sync_users  end  every :day, :at => '3:00am' do -  rake "reflex:sync" +  Cron.sync_reflex  end  every :day, :at => '4:00 am' do -  rake "codifligne:sync" +  Cron.sync_codifligne  end  every 5.minutes do -  rake "import:netex_abort_old" -  rake "import:notify_parent" +  Cron.check_import_operations  end  every 5.minutes do -  rake "compliance_check_sets:abort_old" -  rake "compliance_check_sets:notify_parent" +  Cron.check_ccset_operations  end  every 1.minute do diff --git a/lib/cron.rb b/lib/cron.rb new file mode 100644 index 000000000..0b94c2209 --- /dev/null +++ b/lib/cron.rb @@ -0,0 +1,50 @@ +module Cron +  class << self + +    def sync_organizations +      Organisation.portail_sync +    end + +    def sync_users +      User.portail_sync +    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 if sync.valid? +      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 if sync.valid?  +      rescue => e +        Rails.logger.warn(e.message) +      end +    end + +    def check_import_operations +      begin +        ParentNotifier.new(ComplianceCheckSet).notify_when_finished +        ComplianceCheckSet.abort_old +      rescue => e +        Rails.logger.error(e.inspect) +      end +    end + +    def check_ccset_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 | 
