diff options
| author | Teddy Wing | 2017-08-01 18:39:20 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-08-01 19:19:01 +0200 | 
| commit | de687e374fe29a66fcf2d6f32849a5b7a7ef7646 (patch) | |
| tree | 2b3a32eb9416223a192fca2fdcab797e5c3645ea | |
| parent | eb90176182c8caa3456a5582d2eb0623ce2b210c (diff) | |
| download | chouette-core-de687e374fe29a66fcf2d6f32849a5b7a7ef7646.tar.bz2 | |
schedule.rb: Add cron job to update parent imports from child imports
This task will run every 5 minutes, synchronising parent imports with
the status of their children.
When all children have finished, if none of them have failed, the parent
import should get a status of "successful":
    WorkbenchImport status: :successful
      NetexImport status: :successful
      NetexImport status: :successful
When all children have finished, if any of them have failed, the parent
import should get a status of "failed":
    WorkbenchImport status: :failed
      NetexImport status: :failed
      NetexImport status: :successful
We need a Cron job for this instead of being able to do it via a Ruby
method because the thing that's setting the status on the sub-imports
when they're complete is the STIF Java IEV application. Thus there's no
way for our Ruby code to know that a sub-import has finished. Because of
that, we do this polling mechanism every five minutes to update the
imports that need updating.
Created a Rake task to use in the Whenever schedule because the `runner`
method from Whenever expanded to `script/rails`, which is a bloody
ancient file, and tries to run via JRuby lolwat. Didn't want to bother
adding a configuration to Whenever to use something more modern, and
didn't know whether the binstub in `bin/` for `rails` is available since
we don't commit those to the repo apparently (although I knew that fact
from before).
Refs #3511
| -rw-r--r-- | config/schedule.rb | 4 | ||||
| -rw-r--r-- | lib/tasks/imports.rake | 6 | 
2 files changed, 10 insertions, 0 deletions
| diff --git a/config/schedule.rb b/config/schedule.rb index 83c4d7388..8aa21076f 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -38,3 +38,7 @@ end  every :day, :at => '4:00 am' do    rake "codifligne:sync"  end + +every 5.minutes do +  rake "import:notify_parent" +end diff --git a/lib/tasks/imports.rake b/lib/tasks/imports.rake new file mode 100644 index 000000000..6bc84acc8 --- /dev/null +++ b/lib/tasks/imports.rake @@ -0,0 +1,6 @@ +namespace :import do +  desc "Notify parent imports when children finish" +  task notify_parent: :environment do +    ParentImportNotifier.notify_when_finished +  end +end | 
