aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorTeddy Wing2018-02-06 17:12:09 +0100
committerTeddy Wing2018-02-08 11:29:31 +0100
commitee1781d525bc04aff3f7f743be8297ee003ee9e0 (patch)
treee11097666c6ad27adada3d7cd1df9ba96a19c396 /app
parente07ef0eb9dac728ee5033b42c318692e2368b897 (diff)
downloadchouette-core-ee1781d525bc04aff3f7f743be8297ee003ee9e0.tar.bz2
ComplianceCheckSet: Add `.abort_old`
Copy over the `Import.abort_old` method to this class. For now I haven't bothered with moving it to a consolidated module. We'll see, maybe that's a better approach. For now I'm going with a relaxed copy-paste solution until we decide that the increased complexity of the module is worth the deduplication. We need this method to be able to abort stale imports. We'll be doing this, similarly to imports, in a regular cron job. Refs #4758
Diffstat (limited to 'app')
-rw-r--r--app/models/compliance_check_set.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb
index f4c44d26d..3ea832048 100644
--- a/app/models/compliance_check_set.rb
+++ b/app/models/compliance_check_set.rb
@@ -19,6 +19,18 @@ class ComplianceCheckSet < ActiveRecord::Base
where('created_at BETWEEN :begin AND :end', begin: period_range.begin, end: period_range.end)
end
+ def self.finished_statuses
+ %w(successful failed warning aborted canceled)
+ end
+
+ def self.abort_old
+ where(
+ 'created_at < ? AND status NOT IN (?)',
+ 4.hours.ago,
+ finished_statuses
+ ).update_all(status: 'aborted')
+ end
+
def notify_parent
if parent
# parent.child_change