aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorTeddy Wing2017-08-02 12:36:16 +0200
committerTeddy Wing2017-08-02 12:36:16 +0200
commit533804ec2755ba6564122cb4d43a7f8769d9d1ee (patch)
treea75e06c7d52dfe4d937863ff3ae5029871ac8464 /app
parent0a3221c194115fc039577064590a6f4eb6f33a8a (diff)
downloadchouette-core-533804ec2755ba6564122cb4d43a7f8769d9d1ee.tar.bz2
ParentImportNotifier: Use `Import.finished_statuses`
Instead of manually defining the finished statuses, use the method that's already defined on `Import` to get them. The only unfortunate part is that we now had to muss up our `Import` code and convert those methods to class methods in order for them to be accessible to `ParentImportNotifier` as well as its instance methods. Refs #3511
Diffstat (limited to 'app')
-rw-r--r--app/models/import.rb22
-rw-r--r--app/services/parent_import_notifier.rb2
2 files changed, 12 insertions, 12 deletions
diff --git a/app/models/import.rb b/app/models/import.rb
index 507b40f38..47f41893f 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -13,15 +13,23 @@ class Import < ActiveRecord::Base
before_create :initialize_fields
+ def self.failing_statuses
+ symbols_with_indifferent_access(%i(failed aborted canceled))
+ end
+
+ def self.finished_statuses
+ symbols_with_indifferent_access(%i(successful failed aborted canceled))
+ end
+
def notify_parent
parent.child_change(self)
update(notified_parent_at: DateTime.now)
end
def child_change(child)
- return if finished_statuses.include?(status)
+ return if self.class.finished_statuses.include?(status)
- if failing_statuses.include?(child.status)
+ if self.class.failing_statuses.include?(child.status)
return update(status: 'failed')
end
@@ -39,15 +47,7 @@ class Import < ActiveRecord::Base
self.status = Import.status.new
end
- def failing_statuses
- symbols_with_indifferent_access(%i(failed aborted canceled))
- end
-
- def finished_statuses
- symbols_with_indifferent_access(%i(successful failed aborted canceled))
- end
-
- def symbols_with_indifferent_access(array)
+ def self.symbols_with_indifferent_access(array)
array.flat_map { |symbol| [symbol, symbol.to_s] }
end
end
diff --git a/app/services/parent_import_notifier.rb b/app/services/parent_import_notifier.rb
index 8581cb97a..47e6755e4 100644
--- a/app/services/parent_import_notifier.rb
+++ b/app/services/parent_import_notifier.rb
@@ -8,7 +8,7 @@ class ParentImportNotifier
Import
.where(
notified_parent_at: nil,
- status: [:failed, :successful, :aborted, :canceled]
+ status: Import.finished_statuses
)
.where.not(parent: nil)
end