aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlban Peignier2017-08-28 18:27:00 +0200
committerTeddy Wing2017-08-28 18:33:47 +0200
commit61817b2e7828455021bcec66e2d6da70f879e1c4 (patch)
tree48cd353e993f3b1eb2179773cb92d393c55252f4
parent43c355dc9c5e60398977908109135c6017338537 (diff)
downloadchouette-core-61817b2e7828455021bcec66e2d6da70f879e1c4.tar.bz2
Import#child_change: Move status update logic into a new method
Instead of just looking at the given child, the parent import status is now determined by checking all children and assigning a value based on their status. This also updates the `current_step` (which was previously handled by the `WorkbenchImportWorker`, remind me to remove it from where), and the `ended_at` time. I think `ended_at` should probably be updated in both successful and failed cases. Will have to make that update.
-rw-r--r--app/models/import.rb33
1 files changed, 29 insertions, 4 deletions
diff --git a/app/models/import.rb b/app/models/import.rb
index 755d5a900..27cde2855 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -33,14 +33,39 @@ class Import < ActiveRecord::Base
update(notified_parent_at: DateTime.now)
end
- def child_change(child)
+ def child_change
return if self.class.finished_statuses.include?(status)
- if self.class.failing_statuses.include?(child.status)
- return update(status: 'failed')
+ update_status
+ end
+
+ def update_status
+ status_count = children.group(:status).count
+ children_finished_count = children_failed_count = children_count = 0
+
+ status_count.each do |status, count|
+ if self.class.failing_statuses.include?(status)
+ children_failed_count += count
+ end
+ if self.class.finished_statuses.include?(status)
+ children_finished_count += count
+ end
+ children_count += count
+ end
+
+ attributes = {
+ current_step: children_finished_count
+ }
+
+ status = self.status
+ if children_failed_count > 0
+ status = 'failed'
+ elsif status_count['successful'] == children_count
+ status = 'successful'
+ attributes[:ended_at] = Time.now
end
- update(status: 'successful') if ready?
+ update attributes.merge(status: status)
end
def ready?