diff options
| author | Teddy Wing | 2017-07-25 13:02:26 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-08-01 19:19:01 +0200 |
| commit | eb90176182c8caa3456a5582d2eb0623ce2b210c (patch) | |
| tree | b04d25f23437effc1c4c188cac7a92ffe7aa7edb /app/services | |
| parent | 0e49a76f4510a1bef43445f4e3621e313bd5ea66 (diff) | |
| download | chouette-core-eb90176182c8caa3456a5582d2eb0623ce2b210c.tar.bz2 | |
Add a service that notifies parent imports of sub-import status
A new service, `ParentImportNotifier`, will be called by a Cron job
every 5 minutes. This service will query all finished sub-imports that
haven't yet notified their parent, and tell them to do so.
factories/workbench_imports.rb:
Add a `WorkbenchImport` factory. This is currently incomplete. We'll
want to correctly initialise the `file` attribute eventually.
import.rb:
factories/imports.rb:
In order to get the test setup to work correctly, we skip the
`before_create` callback on `Import`. This is because that callback
initialises `status` to "new". We want to be able to set any status
value in our tests to test things properly. Thus the callback messes
with our buttermilk. For all imports created by the factory, skip this
callback. In order to skip the callback, I had to put it in its own
method and pass the method name to `#skip_callback`. That's why the
callback is now in a new method in `Import`.
Adds an empty `#notify_parent` method in `Import`. For now this doesn't
do anything, but eventually it will be filled in to perform the actual
notification. I this changeset, all we're doing is setting up the
connecting logic to notify the right things from the Cron job.
import_spec.rb:
Remove the `.class_name` validation because we removed that previously
in `Import`. The `belongs_to` is now a polymorphic association, with no
class name specified.
parent_import_notifier_spec.rb:
Needed to use `create` instead of `build_stubbed` in a lot of these
cases so that I could validate the query. Really don't like this because
now this set of tests is SUPER SLOW. If you have any ideas for how to
speed it up, let's do that.
Refs #3511
Diffstat (limited to 'app/services')
| -rw-r--r-- | app/services/parent_import_notifier.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/services/parent_import_notifier.rb b/app/services/parent_import_notifier.rb new file mode 100644 index 000000000..8e6245da9 --- /dev/null +++ b/app/services/parent_import_notifier.rb @@ -0,0 +1,17 @@ +class ParentImportNotifier + def self.notify_when_finished(imports = nil) + imports ||= self.imports_pending_notification + imports.each do |import| + import.notify_parent + end + end + + def self.imports_pending_notification + Import + .where( + notified_parent_at: nil, + status: [:failed, :successful, :aborted, :canceled] + ) + .where.not(parent: nil) + end +end |
