Move the jobs logging handling in ApplicationJob
This commit is contained in:
parent
51f57d983e
commit
0006d42874
5 changed files with 25 additions and 4 deletions
|
@ -1,2 +1,9 @@
|
|||
class ApplicationJob < ActiveJob::Base
|
||||
before_perform do |job|
|
||||
Rails.logger.info("#{job.class.name} started at #{Time.now}")
|
||||
end
|
||||
|
||||
after_perform do |job|
|
||||
Rails.logger.info("#{job.class.name} ended at #{Time.now}")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,6 @@ class AutoArchiveProcedureJob < ApplicationJob
|
|||
queue_as :cron
|
||||
|
||||
def perform(*args)
|
||||
Rails.logger.info("AutoArchiveProcedureJob 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!
|
||||
|
@ -10,6 +9,5 @@ class AutoArchiveProcedureJob < ApplicationJob
|
|||
|
||||
procedure.archive
|
||||
end
|
||||
Rails.logger.info("AutoArchiveProcedureJob ended at #{Time.now}")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,6 @@ class WeeklyOverviewJob < ApplicationJob
|
|||
queue_as :cron
|
||||
|
||||
def perform(*args)
|
||||
Rails.logger.info("WeeklyOverviewJob started at #{Time.now}")
|
||||
# Feature flipped to avoid mails in staging due to unprocessed dossier
|
||||
if Features.weekly_overview
|
||||
Gestionnaire.all
|
||||
|
@ -10,6 +9,5 @@ class WeeklyOverviewJob < ApplicationJob
|
|||
.reject { |_, overview| overview.nil? }
|
||||
.each { |gestionnaire, overview| GestionnaireMailer.last_week_overview(gestionnaire, overview).deliver_now }
|
||||
end
|
||||
Rails.logger.info("WeeklyOverviewJob ended at #{Time.now}")
|
||||
end
|
||||
end
|
||||
|
|
16
spec/jobs/application_job_spec.rb
Normal file
16
spec/jobs/application_job_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require 'rails_helper'
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
RSpec.describe ApplicationJob, type: :job do
|
||||
describe 'perform' do
|
||||
it do
|
||||
expect(Rails.logger).to receive(:info).with(/.+started at.+/)
|
||||
expect(Rails.logger).to receive(:info).with(/.+ended at.+/)
|
||||
perform_enqueued_jobs { ChildJob.perform_later }
|
||||
end
|
||||
end
|
||||
|
||||
class ChildJob < ApplicationJob
|
||||
def perform; end
|
||||
end
|
||||
end
|
|
@ -24,6 +24,8 @@ require 'rspec/rails'
|
|||
# If you are not using ActiveRecord, you can remove this line.
|
||||
ActiveRecord::Migration.maintain_test_schema!
|
||||
|
||||
ActiveJob::Base.queue_adapter = :test
|
||||
|
||||
RSpec.configure do |config|
|
||||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
|
|
Loading…
Reference in a new issue