Skip to content

Commit

Permalink
System archives expired surveys each night
Browse files Browse the repository at this point in the history
  • Loading branch information
aktfrikshun authored Jul 12, 2022
1 parent 1e82162 commit 197993e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ def check_expired
end
end

def self.archive_expired!
Form.where("expiration_date is not null and expiration_date < NOW() and aasm_state <> 'archived'").find_each do |form|
Event.log_event(Event.names[:form_archived], 'Form', form.uuid, "Form #{form.name} archived at #{DateTime.now}", 1)
form.archive!
UserMailer.form_status_changed(form:, action: 'archived').deliver_later
end
end

def set_uuid
self.uuid = SecureRandom.uuid if uuid.blank?
end
Expand Down
4 changes: 4 additions & 0 deletions config/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@
every 1.day, at: '10:30pm' do
rake 'scheduled_jobs:send_two_weeks_until_inactivation_warning'
end

every 1.day, at: '11:00pm' do
rake 'scheduled_jobs:archive_surveys'
end
4 changes: 4 additions & 0 deletions lib/tasks/scheduled_jobs.rake
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ namespace :scheduled_jobs do
task send_two_weeks_until_inactivation_warning: :environment do
User.send_account_deactivation_notifications(14)
end

task archive_surveys: :environment do
Form.archive_expired!
end
end

0 comments on commit 197993e

Please sign in to comment.