Change AutoArchiveProcedureWorker for delayed_job

This commit is contained in:
Mathieu Magnin 2017-09-26 14:12:55 +02:00 committed by Simon Lehericey
parent b9869d861f
commit fbad15bc84
2 changed files with 11 additions and 2 deletions

View file

@ -1,7 +1,6 @@
class AutoArchiveProcedureWorker
include Sidekiq::Worker
def perform(*args)
Rails.logger.info("AutoArchiveProcedureWorker started at #{Time.now}")
Procedure.publiees.where("auto_archive_on <= ?", Date.today).each do |procedure|
procedure.dossiers.state_en_construction.each do |dossier|
dossier.received!
@ -9,5 +8,12 @@ class AutoArchiveProcedureWorker
procedure.archive
end
Rails.logger.info("AutoArchiveProcedureWorker ended at #{Time.now}")
end
def queue_name
"cron"
end
handle_asynchronously :perform
end

View file

@ -1,6 +1,9 @@
require 'rails_helper'
RSpec.describe AutoArchiveProcedureWorker, type: :worker do
before { Delayed::Worker.delay_jobs = false }
after { Delayed::Worker.delay_jobs = true }
let!(:procedure) { create(:procedure, published_at: Time.now, archived_at: nil, auto_archive_on: nil )}
let!(:procedure_hier) { create(:procedure, published_at: Time.now, archived_at: nil, auto_archive_on: 1.day.ago )}
let!(:procedure_aujourdhui) { create(:procedure, published_at: Time.now, archived_at: nil, auto_archive_on: Date.today )}