diff --git a/app/controllers/subscribers_auth_token_controller.rb b/app/controllers/subscribers_auth_token_controller.rb index 3fd39b7aa..21177da67 100644 --- a/app/controllers/subscribers_auth_token_controller.rb +++ b/app/controllers/subscribers_auth_token_controller.rb @@ -10,7 +10,7 @@ def auth_token token = generate_token(subscriber) email = build_email(subscriber, token) - SendEmailWorker + SendEmailJob .perform_async_in_queue(email.id, queue: :send_email_transactional) render json: { subscriber: }, status: :created diff --git a/app/controllers/subscribers_govuk_account_controller.rb b/app/controllers/subscribers_govuk_account_controller.rb index d3f45aebb..7103f9658 100644 --- a/app/controllers/subscribers_govuk_account_controller.rb +++ b/app/controllers/subscribers_govuk_account_controller.rb @@ -26,7 +26,7 @@ def link_subscriber_to_account subscriber:, ) - SendEmailWorker.perform_async_in_queue( + SendEmailJob.perform_async_in_queue( email.id, queue: :send_email_transactional, ) diff --git a/app/controllers/subscriptions_auth_token_controller.rb b/app/controllers/subscriptions_auth_token_controller.rb index 07ad5f570..f85e5191f 100644 --- a/app/controllers/subscriptions_auth_token_controller.rb +++ b/app/controllers/subscriptions_auth_token_controller.rb @@ -8,7 +8,7 @@ def auth_token token = generate_token email = build_email(token, subscriber_list) - SendEmailWorker + SendEmailJob .perform_async_in_queue(email.id, queue: :send_email_transactional) render json: {}, status: :ok diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 51431208f..4324e69d7 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -66,6 +66,6 @@ def send_confirmation_email(subscription) return unless subscription[:new_record] email = SubscriptionConfirmationEmailBuilder.call(subscription: subscription[:record]) - SendEmailWorker.perform_async_in_queue(email.id, queue: :send_email_transactional) + SendEmailJob.perform_async_in_queue(email.id, queue: :send_email_transactional) end end diff --git a/app/workers/application_worker.rb b/app/jobs/application_job.rb similarity index 77% rename from app/workers/application_worker.rb rename to app/jobs/application_job.rb index c370ba40d..fcc9a29d0 100644 --- a/app/workers/application_worker.rb +++ b/app/jobs/application_job.rb @@ -1,5 +1,5 @@ -class ApplicationWorker - include Sidekiq::Worker +class ApplicationJob + include Sidekiq::Job private diff --git a/app/workers/bulk_migrate_list_worker.rb b/app/jobs/bulk_migrate_list_job.rb similarity index 93% rename from app/workers/bulk_migrate_list_worker.rb rename to app/jobs/bulk_migrate_list_job.rb index 098eb5717..4edfdda9d 100644 --- a/app/workers/bulk_migrate_list_worker.rb +++ b/app/jobs/bulk_migrate_list_job.rb @@ -1,4 +1,4 @@ -class BulkMigrateListWorker < ApplicationWorker +class BulkMigrateListJob < ApplicationJob def perform(source_list_id, destination_list_id) @source_list_id = source_list_id @destination_list_id = destination_list_id @@ -67,7 +67,7 @@ def send_confirmation_message destination_id: destination_list.id, count: subscribers_to_move_count, ) - SendEmailWorker.perform_async_in_queue(email.id, queue: :send_email_transactional) + SendEmailJob.perform_async_in_queue(email.id, queue: :send_email_transactional) logger.info("Migration of subscriberlist #{source_list.id} complete. Email with id #{email.id} queued for delivery") end end diff --git a/app/workers/bulk_unsubscribe_list_worker.rb b/app/jobs/bulk_unsubscribe_list_job.rb similarity index 74% rename from app/workers/bulk_unsubscribe_list_worker.rb rename to app/jobs/bulk_unsubscribe_list_job.rb index 505951c7f..dd5c409bf 100644 --- a/app/workers/bulk_unsubscribe_list_worker.rb +++ b/app/jobs/bulk_unsubscribe_list_job.rb @@ -1,9 +1,9 @@ -class BulkUnsubscribeListWorker < ApplicationWorker +class BulkUnsubscribeListJob < ApplicationJob sidekiq_options queue: :process_and_generate_emails def perform(subscriber_list_id, message_id) run_with_advisory_lock(SubscriberList, subscriber_list_id) do - ProcessMessageWorker.new.perform(message_id) if message_id + ProcessMessageJob.new.perform(message_id) if message_id Subscription.active.where(subscriber_list_id:).update_all( ended_reason: :bulk_unsubscribed, diff --git a/app/workers/daily_digest_initiator_worker.rb b/app/jobs/daily_digest_initiator_job.rb similarity index 80% rename from app/workers/daily_digest_initiator_worker.rb rename to app/jobs/daily_digest_initiator_job.rb index fa0130fde..f0b7c0800 100644 --- a/app/workers/daily_digest_initiator_worker.rb +++ b/app/jobs/daily_digest_initiator_job.rb @@ -1,4 +1,4 @@ -class DailyDigestInitiatorWorker < ApplicationWorker +class DailyDigestInitiatorJob < ApplicationJob def perform(date = Date.current.to_s) run_with_advisory_lock(DigestRun, "#{date}-#{Frequency::DAILY}") do DigestInitiatorService.call(date: Date.parse(date), range: Frequency::DAILY) diff --git a/app/workers/digest_email_generation_worker.rb b/app/jobs/digest_email_generation_job.rb similarity index 92% rename from app/workers/digest_email_generation_worker.rb rename to app/jobs/digest_email_generation_job.rb index 7819dfeac..c9ee46fca 100644 --- a/app/workers/digest_email_generation_worker.rb +++ b/app/jobs/digest_email_generation_job.rb @@ -1,4 +1,4 @@ -class DigestEmailGenerationWorker < ApplicationWorker +class DigestEmailGenerationJob < ApplicationJob sidekiq_options queue: :email_generation_digest def perform(digest_run_subscriber_id) @@ -23,7 +23,7 @@ def perform(digest_run_subscriber_id) end email_ids.each do |email_id| - SendEmailWorker.perform_async_in_queue(email_id, queue: :send_email_digest) + SendEmailJob.perform_async_in_queue(email_id, queue: :send_email_digest) end end diff --git a/app/workers/digest_run_completion_marker_worker.rb b/app/jobs/digest_run_completion_marker_job.rb similarity index 82% rename from app/workers/digest_run_completion_marker_worker.rb rename to app/jobs/digest_run_completion_marker_job.rb index e28c2f745..ebd342019 100644 --- a/app/workers/digest_run_completion_marker_worker.rb +++ b/app/jobs/digest_run_completion_marker_job.rb @@ -1,4 +1,4 @@ -class DigestRunCompletionMarkerWorker < ApplicationWorker +class DigestRunCompletionMarkerJob < ApplicationJob def perform candidates = DigestRun.where.not(processed_at: nil).where(completed_at: nil) candidates.find_each do |digest_run| diff --git a/app/workers/email_deletion_worker.rb b/app/jobs/email_deletion_job.rb similarity index 90% rename from app/workers/email_deletion_worker.rb rename to app/jobs/email_deletion_job.rb index 0a395bbd8..81e6c5a52 100644 --- a/app/workers/email_deletion_worker.rb +++ b/app/jobs/email_deletion_job.rb @@ -1,4 +1,4 @@ -class EmailDeletionWorker < ApplicationWorker +class EmailDeletionJob < ApplicationJob def perform run_with_advisory_lock(Email, "delete") do start_time = Time.zone.now diff --git a/app/workers/historical_data_deletion_worker.rb b/app/jobs/historical_data_deletion_job.rb similarity index 96% rename from app/workers/historical_data_deletion_worker.rb rename to app/jobs/historical_data_deletion_job.rb index 2c23d20b2..40d4874ba 100644 --- a/app/workers/historical_data_deletion_worker.rb +++ b/app/jobs/historical_data_deletion_job.rb @@ -1,4 +1,4 @@ -class HistoricalDataDeletionWorker < ApplicationWorker +class HistoricalDataDeletionJob < ApplicationJob def perform # cascades matched content changes delete_and_log("content changes") { ContentChange.where("created_at < ?", max_retention_period) } diff --git a/app/workers/metrics_collection_worker.rb b/app/jobs/metrics_collection_job.rb similarity index 68% rename from app/workers/metrics_collection_worker.rb rename to app/jobs/metrics_collection_job.rb index 938ffe050..97124b1f6 100644 --- a/app/workers/metrics_collection_worker.rb +++ b/app/jobs/metrics_collection_job.rb @@ -1,4 +1,4 @@ -class MetricsCollectionWorker < ApplicationWorker +class MetricsCollectionJob < ApplicationJob def perform ContentChangeExporter.call DigestRunExporter.call diff --git a/app/workers/metrics_collection_worker/base_exporter.rb b/app/jobs/metrics_collection_job/base_exporter.rb similarity index 60% rename from app/workers/metrics_collection_worker/base_exporter.rb rename to app/jobs/metrics_collection_job/base_exporter.rb index 8d6960acd..e2a08890c 100644 --- a/app/workers/metrics_collection_worker/base_exporter.rb +++ b/app/jobs/metrics_collection_job/base_exporter.rb @@ -1,4 +1,4 @@ -class MetricsCollectionWorker::BaseExporter +class MetricsCollectionJob::BaseExporter def self.call new.call end diff --git a/app/workers/metrics_collection_worker/content_change_exporter.rb b/app/jobs/metrics_collection_job/content_change_exporter.rb similarity index 77% rename from app/workers/metrics_collection_worker/content_change_exporter.rb rename to app/jobs/metrics_collection_job/content_change_exporter.rb index 0427d4562..7a62029d3 100644 --- a/app/workers/metrics_collection_worker/content_change_exporter.rb +++ b/app/jobs/metrics_collection_job/content_change_exporter.rb @@ -1,4 +1,4 @@ -class MetricsCollectionWorker::ContentChangeExporter < MetricsCollectionWorker::BaseExporter +class MetricsCollectionJob::ContentChangeExporter < MetricsCollectionJob::BaseExporter def call GovukStatsd.gauge("content_changes.unprocessed_total", unprocessed_content_changes) end diff --git a/app/workers/metrics_collection_worker/digest_run_exporter.rb b/app/jobs/metrics_collection_job/digest_run_exporter.rb similarity index 75% rename from app/workers/metrics_collection_worker/digest_run_exporter.rb rename to app/jobs/metrics_collection_job/digest_run_exporter.rb index 27e2782a7..d5b5c9bf5 100644 --- a/app/workers/metrics_collection_worker/digest_run_exporter.rb +++ b/app/jobs/metrics_collection_job/digest_run_exporter.rb @@ -1,4 +1,4 @@ -class MetricsCollectionWorker::DigestRunExporter < MetricsCollectionWorker::BaseExporter +class MetricsCollectionJob::DigestRunExporter < MetricsCollectionJob::BaseExporter def call critical_digest_runs = DigestRun.where("created_at < ?", 2.hours.ago) .where(completed_at: nil) diff --git a/app/workers/metrics_collection_worker/message_exporter.rb b/app/jobs/metrics_collection_job/message_exporter.rb similarity index 77% rename from app/workers/metrics_collection_worker/message_exporter.rb rename to app/jobs/metrics_collection_job/message_exporter.rb index 60905ef0b..2d01436fb 100644 --- a/app/workers/metrics_collection_worker/message_exporter.rb +++ b/app/jobs/metrics_collection_job/message_exporter.rb @@ -1,4 +1,4 @@ -class MetricsCollectionWorker::MessageExporter < MetricsCollectionWorker::BaseExporter +class MetricsCollectionJob::MessageExporter < MetricsCollectionJob::BaseExporter def call GovukStatsd.gauge("messages.unprocessed_total", unprocessed_messages) end diff --git a/app/workers/nullify_subscribers_worker.rb b/app/jobs/nullify_subscribers_job.rb similarity index 82% rename from app/workers/nullify_subscribers_worker.rb rename to app/jobs/nullify_subscribers_job.rb index 0c0801ddc..649efdd98 100644 --- a/app/workers/nullify_subscribers_worker.rb +++ b/app/jobs/nullify_subscribers_job.rb @@ -1,11 +1,11 @@ -class NullifySubscribersWorker < ApplicationWorker +class NullifySubscribersJob < ApplicationJob def perform run_with_advisory_lock(Subscriber, "nullify") do nullifyable_subscribers.each do |s| begin GdsApi.account_api.delete_user_by_subject_identifier(subject_identifier: s.govuk_account_id) unless s.govuk_account_id.nil? rescue GdsApi::HTTPNotFound - Rails.logger.warn("NullifySubscribersWorker tried to remove account id #{s.govuk_account_id}, but couldn't find it.") + Rails.logger.warn("NullifySubscribersJob tried to remove account id #{s.govuk_account_id}, but couldn't find it.") end s.update!(address: nil, govuk_account_id: nil, updated_at: Time.zone.now) end diff --git a/app/workers/polling_alert_check_worker.rb b/app/jobs/polling_alert_check_job.rb similarity index 96% rename from app/workers/polling_alert_check_worker.rb rename to app/jobs/polling_alert_check_job.rb index 96b9b2c7c..94eb4e7f7 100644 --- a/app/workers/polling_alert_check_worker.rb +++ b/app/jobs/polling_alert_check_job.rb @@ -1,4 +1,4 @@ -class PollingAlertCheckWorker < ApplicationWorker +class PollingAlertCheckJob < ApplicationJob include SearchAlertList def perform(document_type) diff --git a/app/workers/process_content_change_worker.rb b/app/jobs/process_content_change_job.rb similarity index 90% rename from app/workers/process_content_change_worker.rb rename to app/jobs/process_content_change_job.rb index 2c320f317..77be23dc3 100644 --- a/app/workers/process_content_change_worker.rb +++ b/app/jobs/process_content_change_job.rb @@ -1,4 +1,4 @@ -class ProcessContentChangeWorker < ApplicationWorker +class ProcessContentChangeJob < ApplicationJob sidekiq_options queue: :process_and_generate_emails def perform(content_change_id) diff --git a/app/workers/process_message_worker.rb b/app/jobs/process_message_job.rb similarity index 89% rename from app/workers/process_message_worker.rb rename to app/jobs/process_message_job.rb index eb2c4191f..674417626 100644 --- a/app/workers/process_message_worker.rb +++ b/app/jobs/process_message_job.rb @@ -1,4 +1,4 @@ -class ProcessMessageWorker < ApplicationWorker +class ProcessMessageJob < ApplicationJob sidekiq_options queue: :process_and_generate_emails def perform(message_id) diff --git a/app/jobs/recover_lost_jobs_job.rb b/app/jobs/recover_lost_jobs_job.rb new file mode 100644 index 000000000..f8f71814f --- /dev/null +++ b/app/jobs/recover_lost_jobs_job.rb @@ -0,0 +1,7 @@ +class RecoverLostJobsJob < ApplicationJob + def perform + RecoverLostJobsJob::UnprocessedCheck.new.call + RecoverLostJobsJob::MissingDigestRunsCheck.new.call + RecoverLostJobsJob::OldPendingEmailsCheck.new.call + end +end diff --git a/app/workers/recover_lost_jobs_worker/missing_digest_runs_check.rb b/app/jobs/recover_lost_jobs_job/missing_digest_runs_check.rb similarity index 80% rename from app/workers/recover_lost_jobs_worker/missing_digest_runs_check.rb rename to app/jobs/recover_lost_jobs_job/missing_digest_runs_check.rb index 701555106..a8bb7e243 100644 --- a/app/workers/recover_lost_jobs_worker/missing_digest_runs_check.rb +++ b/app/jobs/recover_lost_jobs_job/missing_digest_runs_check.rb @@ -1,7 +1,7 @@ -class RecoverLostJobsWorker::MissingDigestRunsCheck +class RecoverLostJobsJob::MissingDigestRunsCheck def call - recover(DailyDigestInitiatorWorker, non_existent_daily_digests) - recover(WeeklyDigestInitiatorWorker, non_existent_weekly_digests) + recover(DailyDigestInitiatorJob, non_existent_daily_digests) + recover(WeeklyDigestInitiatorJob, non_existent_weekly_digests) end private diff --git a/app/workers/recover_lost_jobs_worker/old_pending_emails_check.rb b/app/jobs/recover_lost_jobs_job/old_pending_emails_check.rb similarity index 71% rename from app/workers/recover_lost_jobs_worker/old_pending_emails_check.rb rename to app/jobs/recover_lost_jobs_job/old_pending_emails_check.rb index a036d2a4b..d297ecab5 100644 --- a/app/workers/recover_lost_jobs_worker/old_pending_emails_check.rb +++ b/app/jobs/recover_lost_jobs_job/old_pending_emails_check.rb @@ -1,4 +1,4 @@ -class RecoverLostJobsWorker::OldPendingEmailsCheck +class RecoverLostJobsJob::OldPendingEmailsCheck def call old_pending_emails = Email.where(status: :pending) .where("created_at <= ?", 3.hours.ago) @@ -11,7 +11,7 @@ def call def recover(old_pending_emails) old_pending_emails.in_batches do |relation| relation.pluck(:id).each do |id| - SendEmailWorker.perform_async_in_queue(id, queue: :send_email_immediate) + SendEmailJob.perform_async_in_queue(id, queue: :send_email_immediate) end end end diff --git a/app/jobs/recover_lost_jobs_job/unprocessed_check.rb b/app/jobs/recover_lost_jobs_job/unprocessed_check.rb new file mode 100644 index 000000000..31314da15 --- /dev/null +++ b/app/jobs/recover_lost_jobs_job/unprocessed_check.rb @@ -0,0 +1,19 @@ +class RecoverLostJobsJob::UnprocessedCheck + def call + recover(ProcessContentChangeJob, old_unprocessed(ContentChange).pluck(:id)) + recover(ProcessMessageJob, old_unprocessed(Message).pluck(:id)) + recover(DigestEmailGenerationJob, old_unprocessed(DigestRunSubscriber).pluck(:id)) + recover(DailyDigestInitiatorJob, old_unprocessed(DigestRun.daily).pluck(:date).map(&:to_s)) + recover(WeeklyDigestInitiatorJob, old_unprocessed(DigestRun.weekly).pluck(:date).map(&:to_s)) + end + +private + + def old_unprocessed(scope) + scope.where(processed_at: nil).where("created_at <= ?", 1.hour.ago) + end + + def recover(worker, work) + work.each { |arg| worker.perform_async(arg) } + end +end diff --git a/app/workers/send_email_worker.rb b/app/jobs/send_email_job.rb similarity index 93% rename from app/workers/send_email_worker.rb rename to app/jobs/send_email_job.rb index 2728e1beb..e2b57fce7 100644 --- a/app/workers/send_email_worker.rb +++ b/app/jobs/send_email_job.rb @@ -1,4 +1,4 @@ -class SendEmailWorker < ApplicationWorker +class SendEmailJob < ApplicationJob # More information around the rate limit can be found here -> # https://docs.publishing.service.gov.uk/manual/govuk-notify.html under "GOV.UK Emails". RATE_LIMIT_THRESHOLD = 21_600 # max requests in a minute, equates to 350 a second @@ -7,7 +7,7 @@ class SendEmailWorker < ApplicationWorker def perform(email_id, metrics, queue) if rate_limit_exceeded? logger.warn("Rescheduling email #{email_id} due to exceeding rate limit") - SendEmailWorker.set(queue: queue || "send_email_immediate") + SendEmailJob.set(queue: queue || "send_email_immediate") .perform_in(5.minutes, email_id, metrics, queue) return end diff --git a/app/workers/subscriber_list_audit_worker.rb b/app/jobs/subscriber_list_audit_job.rb similarity index 94% rename from app/workers/subscriber_list_audit_worker.rb rename to app/jobs/subscriber_list_audit_job.rb index ef17a4b88..a87ca2082 100644 --- a/app/workers/subscriber_list_audit_worker.rb +++ b/app/jobs/subscriber_list_audit_job.rb @@ -1,4 +1,4 @@ -class SubscriberListAuditWorker < ApplicationWorker +class SubscriberListAuditJob < ApplicationJob sidekiq_options queue: :subscriber_list_audit def perform(url_batch, audit_start_time_string) diff --git a/app/workers/weekly_digest_initiator_worker.rb b/app/jobs/weekly_digest_initiator_job.rb similarity index 79% rename from app/workers/weekly_digest_initiator_worker.rb rename to app/jobs/weekly_digest_initiator_job.rb index b92151e6b..c949d6324 100644 --- a/app/workers/weekly_digest_initiator_worker.rb +++ b/app/jobs/weekly_digest_initiator_job.rb @@ -1,4 +1,4 @@ -class WeeklyDigestInitiatorWorker < ApplicationWorker +class WeeklyDigestInitiatorJob < ApplicationJob def perform(date = Date.current.to_s) run_with_advisory_lock(DigestRun, "#{date}-#{Frequency::WEEKLY}") do DigestInitiatorService.call(date: Date.parse(date), range: Frequency::WEEKLY) diff --git a/app/services/bulk_unsubscribe_list_service.rb b/app/services/bulk_unsubscribe_list_service.rb index 53652e67b..d067bd03b 100644 --- a/app/services/bulk_unsubscribe_list_service.rb +++ b/app/services/bulk_unsubscribe_list_service.rb @@ -13,7 +13,7 @@ def initialize(subscriber_list:, params:, govuk_request_id:, user: nil) def call message = Message.create!(message_params) if message_params Metrics.message_created if message - BulkUnsubscribeListWorker.perform_async( + BulkUnsubscribeListJob.perform_async( subscriber_list.id, message&.id, ) diff --git a/app/services/content_change_handler_service.rb b/app/services/content_change_handler_service.rb index 4482a5fbb..d09f4c095 100644 --- a/app/services/content_change_handler_service.rb +++ b/app/services/content_change_handler_service.rb @@ -10,7 +10,7 @@ def initialize(params:, govuk_request_id:, user: nil) def call content_change = ContentChange.create!(content_change_params) Metrics.content_change_created - ProcessContentChangeWorker.perform_async(content_change.id) + ProcessContentChangeJob.perform_async(content_change.id) end private diff --git a/app/services/digest_initiator_service.rb b/app/services/digest_initiator_service.rb index c8b4fb9ab..52f8e5733 100644 --- a/app/services/digest_initiator_service.rb +++ b/app/services/digest_initiator_service.rb @@ -32,7 +32,7 @@ def create_digest_run_subscribers(digest_run) def enqueue_jobs(digest_run_subscriber_ids) digest_run_subscriber_ids.each do |digest_run_subscriber_id| - DigestEmailGenerationWorker.perform_async(digest_run_subscriber_id) + DigestEmailGenerationJob.perform_async(digest_run_subscriber_id) end end end diff --git a/app/services/immediate_email_generation_service.rb b/app/services/immediate_email_generation_service.rb index 85a3a1793..ca13722d7 100644 --- a/app/services/immediate_email_generation_service.rb +++ b/app/services/immediate_email_generation_service.rb @@ -11,7 +11,7 @@ def call subscriber_batches.each do |batch| email_ids = batch.generate_emails email_ids.each do |id| - SendEmailWorker.perform_async_in_queue( + SendEmailJob.perform_async_in_queue( id, worker_metrics, queue: content.queue, diff --git a/app/workers/recover_lost_jobs_worker.rb b/app/workers/recover_lost_jobs_worker.rb deleted file mode 100644 index c2abe0b63..000000000 --- a/app/workers/recover_lost_jobs_worker.rb +++ /dev/null @@ -1,7 +0,0 @@ -class RecoverLostJobsWorker < ApplicationWorker - def perform - RecoverLostJobsWorker::UnprocessedCheck.new.call - RecoverLostJobsWorker::MissingDigestRunsCheck.new.call - RecoverLostJobsWorker::OldPendingEmailsCheck.new.call - end -end diff --git a/app/workers/recover_lost_jobs_worker/unprocessed_check.rb b/app/workers/recover_lost_jobs_worker/unprocessed_check.rb deleted file mode 100644 index 1ff593620..000000000 --- a/app/workers/recover_lost_jobs_worker/unprocessed_check.rb +++ /dev/null @@ -1,19 +0,0 @@ -class RecoverLostJobsWorker::UnprocessedCheck - def call - recover(ProcessContentChangeWorker, old_unprocessed(ContentChange).pluck(:id)) - recover(ProcessMessageWorker, old_unprocessed(Message).pluck(:id)) - recover(DigestEmailGenerationWorker, old_unprocessed(DigestRunSubscriber).pluck(:id)) - recover(DailyDigestInitiatorWorker, old_unprocessed(DigestRun.daily).pluck(:date).map(&:to_s)) - recover(WeeklyDigestInitiatorWorker, old_unprocessed(DigestRun.weekly).pluck(:date).map(&:to_s)) - end - -private - - def old_unprocessed(scope) - scope.where(processed_at: nil).where("created_at <= ?", 1.hour.ago) - end - - def recover(worker, work) - work.each { |arg| worker.perform_async(arg) } - end -end diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 192725a01..8e498a541 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -1,6 +1,3 @@ -# Set strict args so we're ready for Sidekiq 7 -Sidekiq.strict_args! - Sidekiq.configure_server do |config| config.logger.level = Rails.logger.level end diff --git a/config/sidekiq.yml b/config/sidekiq.yml index 3abdbe19f..2433ee556 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -18,33 +18,33 @@ :schedule: daily_digest_initiator: cron: '30 8 * * * Europe/London' # every day at 8:30am - class: DailyDigestInitiatorWorker + class: DailyDigestInitiatorJob weekly_digest_initiator: cron: '30 8 * * 6 Europe/London' # every Saturday at 8:30am - class: WeeklyDigestInitiatorWorker + class: WeeklyDigestInitiatorJob historical_data_deletion: cron: '0 12 * * * Europe/London' # every day at midday - class: HistoricalDataDeletionWorker + class: HistoricalDataDeletionJob nullify_subscribers: every: '1h' - class: NullifySubscribersWorker + class: NullifySubscribersJob email_deleter: every: '1h' - class: EmailDeletionWorker + class: EmailDeletionJob digest_run_completion_marker: every: '1m' - class: DigestRunCompletionMarkerWorker + class: DigestRunCompletionMarkerJob metrics_collection: every: '1m' - class: MetricsCollectionWorker + class: MetricsCollectionJob recover_lost_jobs: every: '30m' - class: RecoverLostJobsWorker + class: RecoverLostJobsJob check_medical_safety_alerts: every: '15m' - class: PollingAlertCheckWorker + class: PollingAlertCheckJob args: ["medical_safety_alert"] check_travel_advice_alerts: every: '15m' - class: PollingAlertCheckWorker + class: PollingAlertCheckJob args: ["travel_advice"] diff --git a/docs/alert_check_scheduled_jobs.md b/docs/alert_check_scheduled_jobs.md index 8af557a38..d4425f2ac 100644 --- a/docs/alert_check_scheduled_jobs.md +++ b/docs/alert_check_scheduled_jobs.md @@ -46,7 +46,7 @@ kubectl -n apps deploy/email-alert-api -- rails c (Rails console) > Email.where(content_id: ).delete_all -> PollingAlertCheckWorker.new.perform() +> PollingAlertCheckJob.new.perform() ``` The alert check worker will find no emails with notify status "delivered", and nothing to actively poll (no emails with notify status nil), and will set the alert metric. Prometheus should collect the metrics after a minute, and set off the alert. diff --git a/lib/subscriber_list_mover.rb b/lib/subscriber_list_mover.rb index 64bff0ea9..e15568e8a 100644 --- a/lib/subscriber_list_mover.rb +++ b/lib/subscriber_list_mover.rb @@ -24,7 +24,7 @@ def call ) end - BulkMigrateListWorker.perform_async( + BulkMigrateListJob.perform_async( source_subscriber_list.id, destination_subscriber_list.id, ) @@ -33,7 +33,7 @@ def call if send_email puts "Sending emails to subscribers about change" - emails.each { |id| SendEmailWorker.perform_async_in_queue(id, queue: :send_email_immediate) } + emails.each { |id| SendEmailJob.perform_async_in_queue(id, queue: :send_email_immediate) } end end diff --git a/lib/tasks/bulk_email.rake b/lib/tasks/bulk_email.rake index d5e412cf9..287197990 100644 --- a/lib/tasks/bulk_email.rake +++ b/lib/tasks/bulk_email.rake @@ -8,7 +8,7 @@ namespace :bulk_email do subscriber_lists:, ) email_ids.each do |id| - SendEmailWorker.perform_async_in_queue(id, queue: :send_email_immediate) + SendEmailJob.perform_async_in_queue(id, queue: :send_email_immediate) end puts "Sending #{email_ids.count} emails to subscribers on the following lists: #{subscriber_lists.pluck(:slug).join(', ')}" end @@ -22,7 +22,7 @@ namespace :bulk_email do subscriber_lists:, ) email_ids.each do |id| - SendEmailWorker.perform_async_in_queue(id, queue: :send_email_immediate) + SendEmailJob.perform_async_in_queue(id, queue: :send_email_immediate) end puts "Sending #{email_ids.count} emails to subscribers on the following lists: #{subscriber_lists.pluck(:slug).join(', ')}" end diff --git a/lib/tasks/subscriber_list_audit.rake b/lib/tasks/subscriber_list_audit.rake index d745fbb7f..a513c6d56 100644 --- a/lib/tasks/subscriber_list_audit.rake +++ b/lib/tasks/subscriber_list_audit.rake @@ -20,7 +20,7 @@ namespace :subscriber_list_audit do puts("Read #{urls.count} URLs from sitemap section #{sitemap_url}") urls.each_slice(batch_size) do |batch| - SubscriberListAuditWorker.perform_async(batch, audit_start_time.to_s) + SubscriberListAuditJob.perform_async(batch, audit_start_time.to_s) end end diff --git a/lib/tasks/support.rake b/lib/tasks/support.rake index 6320c2b13..846ef6c48 100644 --- a/lib/tasks/support.rake +++ b/lib/tasks/support.rake @@ -103,7 +103,7 @@ namespace :support do subject: "Test email", body: "This is a test email.", ) - SendEmailWorker.perform_async_in_queue(email.id, queue: :send_email_immediate) + SendEmailJob.perform_async_in_queue(email.id, queue: :send_email_immediate) end namespace :resend_failed_emails do @@ -115,7 +115,7 @@ namespace :support do puts "Resending #{ids.length} emails" ids.each do |id| - SendEmailWorker.perform_async_in_queue(id, queue: :send_email_immediate_high) + SendEmailJob.perform_async_in_queue(id, queue: :send_email_immediate_high) end end @@ -129,7 +129,7 @@ namespace :support do puts "Resending #{ids.length} emails" ids.each do |id| - SendEmailWorker.perform_async_in_queue(id, queue: :send_email_immediate_high) + SendEmailJob.perform_async_in_queue(id, queue: :send_email_immediate_high) end end end diff --git a/spec/features/daily_digest_spec.rb b/spec/features/daily_digest_spec.rb index 50abab444..f6d102202 100644 --- a/spec/features/daily_digest_spec.rb +++ b/spec/features/daily_digest_spec.rb @@ -41,8 +41,8 @@ end travel_to(Time.zone.parse("2017-01-02 10:00")) do - DailyDigestInitiatorWorker.new.perform - Sidekiq::Worker.drain_all + DailyDigestInitiatorJob.new.perform + Sidekiq::Job.drain_all end email_data = expect_an_email_was_sent( @@ -79,8 +79,8 @@ end travel_to(Time.zone.parse("2017-01-02 10:00")) do - DailyDigestInitiatorWorker.new.perform - Sidekiq::Worker.drain_all + DailyDigestInitiatorJob.new.perform + Sidekiq::Job.drain_all end expect_an_email_was_sent( diff --git a/spec/features/unsubscribing_spec.rb b/spec/features/unsubscribing_spec.rb index 643c59ffe..ab17332da 100644 --- a/spec/features/unsubscribing_spec.rb +++ b/spec/features/unsubscribing_spec.rb @@ -7,8 +7,8 @@ travel_to(Time.zone.yesterday.midday) { create_content_change } travel_to(Time.zone.today.midday) do - DailyDigestInitiatorWorker.new.perform - Sidekiq::Worker.drain_all + DailyDigestInitiatorJob.new.perform + Sidekiq::Job.drain_all end email_data = expect_an_email_was_sent @@ -19,8 +19,8 @@ travel_to(Time.zone.today.midnight) { create_content_change } travel_to(Time.zone.tomorrow.midday) do - DailyDigestInitiatorWorker.new.perform - Sidekiq::Worker.drain_all + DailyDigestInitiatorJob.new.perform + Sidekiq::Job.drain_all end expect_an_email_was_not_sent diff --git a/spec/features/weekly_digest_spec.rb b/spec/features/weekly_digest_spec.rb index cda6dcbac..9e02adb0c 100644 --- a/spec/features/weekly_digest_spec.rb +++ b/spec/features/weekly_digest_spec.rb @@ -45,8 +45,8 @@ end travel_to(Time.zone.parse("2017-01-07 10:00")) do - WeeklyDigestInitiatorWorker.new.perform - Sidekiq::Worker.drain_all + WeeklyDigestInitiatorJob.new.perform + Sidekiq::Job.drain_all end email_data = expect_an_email_was_sent( @@ -83,8 +83,8 @@ end travel_to(Time.zone.parse("2017-01-07 10:00")) do - WeeklyDigestInitiatorWorker.new.perform - Sidekiq::Worker.drain_all + WeeklyDigestInitiatorJob.new.perform + Sidekiq::Job.drain_all end expect_an_email_was_sent( diff --git a/spec/integration/subscribers_auth_token_spec.rb b/spec/integration/subscribers_auth_token_spec.rb index 317132103..777f49cec 100644 --- a/spec/integration/subscribers_auth_token_spec.rb +++ b/spec/integration/subscribers_auth_token_spec.rb @@ -26,7 +26,7 @@ end it "sends an email" do - expect(SendEmailWorker).to receive(:perform_async_in_queue) + expect(SendEmailJob).to receive(:perform_async_in_queue) post path, params: end diff --git a/spec/integration/subscribers_govuk_account_spec.rb b/spec/integration/subscribers_govuk_account_spec.rb index 3495085ff..e9c28d721 100644 --- a/spec/integration/subscribers_govuk_account_spec.rb +++ b/spec/integration/subscribers_govuk_account_spec.rb @@ -143,7 +143,7 @@ end it "does not send an email" do - expect(SendEmailWorker).not_to receive(:perform_async_in_queue) + expect(SendEmailJob).not_to receive(:perform_async_in_queue) post path, params: end @@ -153,7 +153,7 @@ end it "sends an email" do - expect(SendEmailWorker).to receive(:perform_async_in_queue) + expect(SendEmailJob).to receive(:perform_async_in_queue) post path, params: end end @@ -174,7 +174,7 @@ end it "does not send an email" do - expect(SendEmailWorker).not_to receive(:perform_async_in_queue) + expect(SendEmailJob).not_to receive(:perform_async_in_queue) post path, params: end end @@ -190,7 +190,7 @@ end it "does not send an email" do - expect(SendEmailWorker).not_to receive(:perform_async_in_queue) + expect(SendEmailJob).not_to receive(:perform_async_in_queue) post path, params: end end diff --git a/spec/integration/subscriptions_auth_token_spec.rb b/spec/integration/subscriptions_auth_token_spec.rb index 0d89e8732..3cbed784f 100644 --- a/spec/integration/subscriptions_auth_token_spec.rb +++ b/spec/integration/subscriptions_auth_token_spec.rb @@ -84,7 +84,7 @@ end it "sends the email" do - expect(SendEmailWorker).to receive(:perform_async_in_queue) + expect(SendEmailJob).to receive(:perform_async_in_queue) post path, params: end diff --git a/spec/workers/bulk_migrate_list_worker_spec.rb b/spec/jobs/bulk_migrate_list_job_spec.rb similarity index 87% rename from spec/workers/bulk_migrate_list_worker_spec.rb rename to spec/jobs/bulk_migrate_list_job_spec.rb index e1bf50066..39a47c214 100644 --- a/spec/workers/bulk_migrate_list_worker_spec.rb +++ b/spec/jobs/bulk_migrate_list_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe BulkMigrateListWorker do +RSpec.describe BulkMigrateListJob do let!(:source_list) { create(:subscriber_list) } let!(:destination_list) { create(:subscriber_list) } @@ -39,11 +39,11 @@ end it "queues a confirmation email when the migration is complete" do - allow(SendEmailWorker).to receive(:perform_async_in_queue) + allow(SendEmailJob).to receive(:perform_async_in_queue) described_class.new.perform(source_list.id, destination_list.id) expect(Email.last.subject).to eq("Bulk migration of #{source_list.title} is complete") - expect(SendEmailWorker).to have_received(:perform_async_in_queue).with(Email.last.id, queue: :send_email_transactional) + expect(SendEmailJob).to have_received(:perform_async_in_queue).with(Email.last.id, queue: :send_email_transactional) end end end diff --git a/spec/workers/bulk_unsubscribe_list_worker_spec.rb b/spec/jobs/bulk_unsubscribe_list_job_spec.rb similarity index 84% rename from spec/workers/bulk_unsubscribe_list_worker_spec.rb rename to spec/jobs/bulk_unsubscribe_list_job_spec.rb index 1caec2f6d..8e1d667c7 100644 --- a/spec/workers/bulk_unsubscribe_list_worker_spec.rb +++ b/spec/jobs/bulk_unsubscribe_list_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe BulkUnsubscribeListWorker do +RSpec.describe BulkUnsubscribeListJob do let(:message) { nil } let!(:subscriber_list) { create(:subscriber_list) } @@ -33,11 +33,11 @@ ) end - it "delegates to ProcessMessageWorker" do - doub = instance_double(ProcessMessageWorker) + it "delegates to ProcessMessageJob" do + doub = instance_double(ProcessMessageJob) expect(doub).to receive(:perform).with(message.id) - expect(ProcessMessageWorker).to receive(:new).and_return(doub) + expect(ProcessMessageJob).to receive(:new).and_return(doub) described_class.new.perform(subscriber_list.id, message.id) end diff --git a/spec/workers/daily_digest_initiator_worker_spec.rb b/spec/jobs/daily_digest_initiator_job_spec.rb similarity index 83% rename from spec/workers/daily_digest_initiator_worker_spec.rb rename to spec/jobs/daily_digest_initiator_job_spec.rb index 60954e259..ba49c1bc7 100644 --- a/spec/workers/daily_digest_initiator_worker_spec.rb +++ b/spec/jobs/daily_digest_initiator_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe DailyDigestInitiatorWorker do +RSpec.describe DailyDigestInitiatorJobs do describe ".perform" do it "calls the daily digest initiator service" do expect(DigestInitiatorService).to receive(:call) diff --git a/spec/workers/digest_email_generation_worker_spec.rb b/spec/jobs/digest_email_generation_job_spec.rb similarity index 97% rename from spec/workers/digest_email_generation_worker_spec.rb rename to spec/jobs/digest_email_generation_job_spec.rb index ef4e51ca6..c3b867a44 100644 --- a/spec/workers/digest_email_generation_worker_spec.rb +++ b/spec/jobs/digest_email_generation_job_spec.rb @@ -59,7 +59,7 @@ end it "enqueues delivery" do - expect(SendEmailWorker).to receive(:perform_async_in_queue) + expect(SendEmailJob).to receive(:perform_async_in_queue) .with(instance_of(String), queue: :send_email_digest) .exactly(2).times diff --git a/spec/workers/digest_run_completion_marker_worker_spec.rb b/spec/jobs/digest_run_completion_marker_job_spec.rb similarity index 95% rename from spec/workers/digest_run_completion_marker_worker_spec.rb rename to spec/jobs/digest_run_completion_marker_job_spec.rb index 7a685630c..e3bcb2306 100644 --- a/spec/workers/digest_run_completion_marker_worker_spec.rb +++ b/spec/jobs/digest_run_completion_marker_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe DigestRunCompletionMarkerWorker, type: :worker do +RSpec.describe DigestRunCompletionMarkerJob, type: :worker do describe "#perform" do context "when a digest run is processed and has processed subscribers" do let(:digest_run) { create(:digest_run, processed_at: Time.zone.now) } diff --git a/spec/workers/email_deletion_worker_spec.rb b/spec/jobs/email_deletion_job_spec.rb similarity index 93% rename from spec/workers/email_deletion_worker_spec.rb rename to spec/jobs/email_deletion_job_spec.rb index 4c5ab69ee..9dd8ff8a5 100644 --- a/spec/workers/email_deletion_worker_spec.rb +++ b/spec/jobs/email_deletion_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe EmailDeletionWorker do +RSpec.describe EmailDeletionJob do describe "#perform" do def perform described_class.new.perform diff --git a/spec/workers/historical_data_deletion_worker_spec.rb b/spec/jobs/historical_data_deletion_job_spec.rb similarity index 98% rename from spec/workers/historical_data_deletion_worker_spec.rb rename to spec/jobs/historical_data_deletion_job_spec.rb index cc69dbea7..f3b492124 100644 --- a/spec/workers/historical_data_deletion_worker_spec.rb +++ b/spec/jobs/historical_data_deletion_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe HistoricalDataDeletionWorker do +RSpec.describe HistoricalDataDeletionJob do describe "#perform" do let(:historic_date) { 2.years.ago } diff --git a/spec/workers/metrics_collection_worker/content_change_exporter_spec.rb b/spec/jobs/metrics_collection_job/content_change_exporter_spec.rb similarity index 85% rename from spec/workers/metrics_collection_worker/content_change_exporter_spec.rb rename to spec/jobs/metrics_collection_job/content_change_exporter_spec.rb index f4f5d1098..2fc6cb9a3 100644 --- a/spec/workers/metrics_collection_worker/content_change_exporter_spec.rb +++ b/spec/jobs/metrics_collection_job/content_change_exporter_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe MetricsCollectionWorker::ContentChangeExporter do +RSpec.describe MetricsCollectionJob::ContentChangeExporter do describe ".call" do let(:statsd) { double } diff --git a/spec/workers/metrics_collection_worker/digest_run_exporter_spec.rb b/spec/jobs/metrics_collection_job/digest_run_exporter_spec.rb similarity index 88% rename from spec/workers/metrics_collection_worker/digest_run_exporter_spec.rb rename to spec/jobs/metrics_collection_job/digest_run_exporter_spec.rb index 6dc89687f..06e6eca48 100644 --- a/spec/workers/metrics_collection_worker/digest_run_exporter_spec.rb +++ b/spec/jobs/metrics_collection_job/digest_run_exporter_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe MetricsCollectionWorker::DigestRunExporter do +RSpec.describe MetricsCollectionJob::DigestRunExporter do describe ".call" do it "records number of unprocessed digest runs over 2 hours old (critical)" do # Digest runs must be created after 8am to validate diff --git a/spec/workers/metrics_collection_worker/message_exporter_spec.rb b/spec/jobs/metrics_collection_job/message_exporter_spec.rb similarity index 86% rename from spec/workers/metrics_collection_worker/message_exporter_spec.rb rename to spec/jobs/metrics_collection_job/message_exporter_spec.rb index 7842ddcb8..c6e86e81d 100644 --- a/spec/workers/metrics_collection_worker/message_exporter_spec.rb +++ b/spec/jobs/metrics_collection_job/message_exporter_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe MetricsCollectionWorker::MessageExporter do +RSpec.describe MetricsCollectionJob::MessageExporter do describe ".call" do let(:statsd) { double } diff --git a/spec/jobs/metrics_collection_job_spec.rb b/spec/jobs/metrics_collection_job_spec.rb new file mode 100644 index 000000000..2a53e7334 --- /dev/null +++ b/spec/jobs/metrics_collection_job_spec.rb @@ -0,0 +1,11 @@ +RSpec.describe MetricsCollectionJob do + describe ".perform" do + it "delegates to collect metrics" do + expect(MetricsCollectionJob::ContentChangeExporter).to receive(:call) + expect(MetricsCollectionJob::DigestRunExporter).to receive(:call) + expect(MetricsCollectionJob::MessageExporter).to receive(:call) + + subject.perform + end + end +end diff --git a/spec/workers/nullify_subscribers_worker_spec.rb b/spec/jobs/nullify_subscribers_job_spec.rb similarity index 98% rename from spec/workers/nullify_subscribers_worker_spec.rb rename to spec/jobs/nullify_subscribers_job_spec.rb index f70c37ec5..b8967fd87 100644 --- a/spec/workers/nullify_subscribers_worker_spec.rb +++ b/spec/jobs/nullify_subscribers_job_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" require "gds_api/test_helpers/account_api" -RSpec.describe NullifySubscribersWorker do +RSpec.describe NullifySubscribersJobs do include GdsApi::TestHelpers::AccountApi describe ".perform" do diff --git a/spec/workers/polling_alert_check_worker_spec.rb b/spec/jobs/polling_alert_check_job_spec.rb similarity index 98% rename from spec/workers/polling_alert_check_worker_spec.rb rename to spec/jobs/polling_alert_check_job_spec.rb index 46fa941ee..a350a241e 100644 --- a/spec/workers/polling_alert_check_worker_spec.rb +++ b/spec/jobs/polling_alert_check_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe PollingAlertCheckWorker do +RSpec.describe PollingAlertCheckJob do include SearchAlertListHelpers include NotifyRequestHelpers diff --git a/spec/workers/process_content_change_worker_spec.rb b/spec/jobs/process_content_change_job_spec.rb similarity index 92% rename from spec/workers/process_content_change_worker_spec.rb rename to spec/jobs/process_content_change_job_spec.rb index abbd3968b..5f9c604a0 100644 --- a/spec/workers/process_content_change_worker_spec.rb +++ b/spec/jobs/process_content_change_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe ProcessContentChangeWorker do +RSpec.describe ProcessContentChangeJob do let(:content_change) do create(:content_change, tags: { tribunal_decision_categories: %w[transfer-of-undertakings] }) end @@ -37,7 +37,7 @@ processed_content = create(:content_change, processed_at: Time.zone.now) expect(ImmediateEmailGenerationService).not_to receive(:call) - expect(SendEmailWorker).not_to receive(:perform_async_in_queue) + expect(SendEmailJob).not_to receive(:perform_async_in_queue) described_class.new.perform(processed_content.id) end diff --git a/spec/workers/process_message_worker_spec.rb b/spec/jobs/process_message_job_spec.rb similarity index 92% rename from spec/workers/process_message_worker_spec.rb rename to spec/jobs/process_message_job_spec.rb index 60a83ae1a..1a7615d2a 100644 --- a/spec/workers/process_message_worker_spec.rb +++ b/spec/jobs/process_message_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe ProcessMessageWorker do +RSpec.describe ProcessMessageJob do let(:message) do create( :message, @@ -38,7 +38,7 @@ processed_message = create(:message, processed_at: Time.zone.now) expect(ImmediateEmailGenerationService).not_to receive(:call) - expect(SendEmailWorker).not_to receive(:perform_async_in_queue) + expect(SendEmailJob).not_to receive(:perform_async_in_queue) described_class.new.perform(processed_message.id) end diff --git a/spec/workers/recover_lost_jobs_worker/missing_digest_runs_check_spec.rb b/spec/jobs/recover_lost_jobs_job/missing_digest_runs_check_spec.rb similarity index 94% rename from spec/workers/recover_lost_jobs_worker/missing_digest_runs_check_spec.rb rename to spec/jobs/recover_lost_jobs_job/missing_digest_runs_check_spec.rb index 7a43cb507..b5efe0919 100644 --- a/spec/workers/recover_lost_jobs_worker/missing_digest_runs_check_spec.rb +++ b/spec/jobs/recover_lost_jobs_job/missing_digest_runs_check_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe RecoverLostJobsWorker::MissingDigestRunsCheck do +RSpec.describe RecoverLostJobsJob::MissingDigestRunsCheck do describe "#call" do it "can create missing work for the week" do tuesday = Time.zone.parse("2017-01-10 10:30") diff --git a/spec/workers/recover_lost_jobs_worker/old_pending_emails_check_spec.rb b/spec/jobs/recover_lost_jobs_job/old_pending_emails_check_spec.rb similarity index 68% rename from spec/workers/recover_lost_jobs_worker/old_pending_emails_check_spec.rb rename to spec/jobs/recover_lost_jobs_job/old_pending_emails_check_spec.rb index a9c45dbc7..8b08ff4fe 100644 --- a/spec/workers/recover_lost_jobs_worker/old_pending_emails_check_spec.rb +++ b/spec/jobs/recover_lost_jobs_job/old_pending_emails_check_spec.rb @@ -1,8 +1,8 @@ -RSpec.describe RecoverLostJobsWorker::OldPendingEmailsCheck do +RSpec.describe RecoverLostJobsJob::OldPendingEmailsCheck do describe "#call" do it "recovers pending emails over an hour old" do email = create(:email, created_at: 4.hours.ago) - expect(SendEmailWorker) + expect(SendEmailJob) .to receive(:perform_async_in_queue) .with(email.id, queue: :send_email_immediate) @@ -11,13 +11,13 @@ it "does not recover recent pending emails" do create(:email, created_at: 2.hours.ago) - expect(SendEmailWorker).to_not receive(:perform_async_in_queue) + expect(SendEmailJob).to_not receive(:perform_async_in_queue) subject.call end it "does not recover emails that aren't pending" do create(:email, created_at: 4.hours.ago, status: :sent) - expect(ProcessContentChangeWorker).not_to receive(:perform_async_in_queue) + expect(ProcessContentChangeJob).not_to receive(:perform_async_in_queue) subject.call end end diff --git a/spec/workers/recover_lost_jobs_worker/unprocessed_check_spec.rb b/spec/jobs/recover_lost_jobs_job/unprocessed_check_spec.rb similarity index 65% rename from spec/workers/recover_lost_jobs_worker/unprocessed_check_spec.rb rename to spec/jobs/recover_lost_jobs_job/unprocessed_check_spec.rb index 45b73dd9a..4b61350cc 100644 --- a/spec/workers/recover_lost_jobs_worker/unprocessed_check_spec.rb +++ b/spec/jobs/recover_lost_jobs_job/unprocessed_check_spec.rb @@ -1,32 +1,32 @@ -RSpec.describe RecoverLostJobsWorker::UnprocessedCheck do +RSpec.describe RecoverLostJobsJob::UnprocessedCheck do describe "#call" do it "recovers unprocessed work over an hour old" do work = create(:content_change, created_at: 1.hour.ago, processed_at: nil) - expect(ProcessContentChangeWorker).to receive(:perform_async).with(work.id) + expect(ProcessContentChangeJob).to receive(:perform_async).with(work.id) subject.call end it "does not recover more recent unprocessed work" do create(:content_change, created_at: 59.minutes.ago, processed_at: nil) - expect(ProcessContentChangeWorker).not_to receive(:perform_async) + expect(ProcessContentChangeJob).not_to receive(:perform_async) subject.call end it "does not recover work that is already processed" do create(:content_change, created_at: 2.hours.ago, processed_at: 1.hour.ago) - expect(ProcessContentChangeWorker).not_to receive(:perform_async) + expect(ProcessContentChangeJob).not_to receive(:perform_async) subject.call end it "can also recover Messages" do work = create(:message, created_at: 1.hour.ago, processed_at: nil) - expect(ProcessMessageWorker).to receive(:perform_async).with(work.id) + expect(ProcessMessageJob).to receive(:perform_async).with(work.id) subject.call end it "can also recover DigestRunSubscribers" do work = create(:digest_run_subscriber, created_at: 1.hour.ago, processed_at: nil) - expect(DigestEmailGenerationWorker).to receive(:perform_async).with(work.id) + expect(DigestEmailGenerationJob).to receive(:perform_async).with(work.id) subject.call end @@ -37,8 +37,8 @@ work1 = create(:digest_run, created_at: 1.hour.ago, date: Date.current, range: :daily) work2 = create(:digest_run, created_at: 1.hour.ago, date: Date.current, range: :weekly) - expect(DailyDigestInitiatorWorker).to receive(:perform_async).with(work1.date.to_s) - expect(WeeklyDigestInitiatorWorker).to receive(:perform_async).with(work2.date.to_s) + expect(DailyDigestInitiatorJob).to receive(:perform_async).with(work1.date.to_s) + expect(WeeklyDigestInitiatorJob).to receive(:perform_async).with(work2.date.to_s) subject.call end diff --git a/spec/jobs/recover_lost_jobs_job_spec.rb b/spec/jobs/recover_lost_jobs_job_spec.rb new file mode 100644 index 000000000..557962edd --- /dev/null +++ b/spec/jobs/recover_lost_jobs_job_spec.rb @@ -0,0 +1,11 @@ +RSpec.describe RecoverLostJobsJob do + describe "#perform" do + it "delegates recovery" do + expect_any_instance_of(RecoverLostJobsJob::UnprocessedCheck).to receive(:call) + expect_any_instance_of(RecoverLostJobsJob::MissingDigestRunsCheck).to receive(:call) + expect_any_instance_of(RecoverLostJobsJob::OldPendingEmailsCheck).to receive(:call) + + subject.perform + end + end +end diff --git a/spec/workers/send_email_worker_spec.rb b/spec/jobs/send_email_job_spec.rb similarity index 98% rename from spec/workers/send_email_worker_spec.rb rename to spec/jobs/send_email_job_spec.rb index 26c303826..db9764692 100644 --- a/spec/workers/send_email_worker_spec.rb +++ b/spec/jobs/send_email_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe SendEmailWorker do +RSpec.describe SendEmailJob do let(:rate_limiter) do instance_double(Ratelimit, exceeded?: false, add: nil) end diff --git a/spec/workers/subscriber_list_audit_worker_spec.rb b/spec/jobs/subscriber_list_audit_job_spec.rb similarity index 98% rename from spec/workers/subscriber_list_audit_worker_spec.rb rename to spec/jobs/subscriber_list_audit_job_spec.rb index 12e78b8d1..fbce030d6 100644 --- a/spec/workers/subscriber_list_audit_worker_spec.rb +++ b/spec/jobs/subscriber_list_audit_job_spec.rb @@ -1,6 +1,6 @@ require "gds_api/test_helpers/content_store" -RSpec.describe SubscriberListAuditWorker do +RSpec.describe SubscriberListAuditJob do include GdsApi::TestHelpers::ContentStore let(:required_match_attributes) do diff --git a/spec/workers/weekly_digest_initiator_worker_spec.rb b/spec/jobs/weekly_digest_initiator_job_spec.rb similarity index 83% rename from spec/workers/weekly_digest_initiator_worker_spec.rb rename to spec/jobs/weekly_digest_initiator_job_spec.rb index 7bd7bb9f2..d96381022 100644 --- a/spec/workers/weekly_digest_initiator_worker_spec.rb +++ b/spec/jobs/weekly_digest_initiator_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe WeeklyDigestInitiatorWorker do +RSpec.describe WeeklyDigestInitiatorJob do describe ".perform" do it "calls the weekly digest initiator service" do expect(DigestInitiatorService).to receive(:call) diff --git a/spec/lib/subscriber_list_mover_spec.rb b/spec/lib/subscriber_list_mover_spec.rb index 747d43cef..1b9313aea 100644 --- a/spec/lib/subscriber_list_mover_spec.rb +++ b/spec/lib/subscriber_list_mover_spec.rb @@ -8,7 +8,7 @@ list_2.subscriptions << create_list(:subscription, 1) allow($stdout).to receive(:puts) - allow(SendEmailWorker).to receive(:perform_async_in_queue) + allow(SendEmailJob).to receive(:perform_async_in_queue) end around(:each) do |example| @@ -64,7 +64,7 @@ destination_id: destination_subscriber_list.id, count: 2) - expect(SendEmailWorker) + expect(SendEmailJob) .to receive(:perform_async_in_queue) .with(email.id, queue: :send_email_transactional) @@ -83,11 +83,11 @@ body: anything, subscriber_lists: source_subscriber_list) - expect(SendEmailWorker) + expect(SendEmailJob) .to receive(:perform_async_in_queue) .with(1, queue: :send_email_immediate) - expect(SendEmailWorker) + expect(SendEmailJob) .to receive(:perform_async_in_queue) .with(2, queue: :send_email_immediate) diff --git a/spec/lib/tasks/bulk_email_spec.rb b/spec/lib/tasks/bulk_email_spec.rb index 3e4fd400c..98f2065cb 100644 --- a/spec/lib/tasks/bulk_email_spec.rb +++ b/spec/lib/tasks/bulk_email_spec.rb @@ -29,11 +29,11 @@ allow(BulkSubscriberListEmailBuilder).to receive(:call) .and_return([1, 2]) - expect(SendEmailWorker) + expect(SendEmailJob) .to receive(:perform_async_in_queue) .with(1, queue: :send_email_immediate) - expect(SendEmailWorker) + expect(SendEmailJob) .to receive(:perform_async_in_queue) .with(2, queue: :send_email_immediate) diff --git a/spec/lib/tasks/support_spec.rb b/spec/lib/tasks/support_spec.rb index 90e2e4bb8..1b8ae6615 100644 --- a/spec/lib/tasks/support_spec.rb +++ b/spec/lib/tasks/support_spec.rb @@ -39,7 +39,7 @@ describe "send_test_email" do it "queues a test email to a test email address" do - expect(SendEmailWorker).to receive(:perform_async_in_queue) + expect(SendEmailJob).to receive(:perform_async_in_queue) expect { Rake::Task["support:send_test_email"].invoke("foo@bar.com") } .to change { Email.count }.by 1 @@ -59,7 +59,7 @@ it "queues specified failed emails to resend" do email = create :email, status: :failed - expect(SendEmailWorker).to receive(:perform_async_in_queue) + expect(SendEmailJob).to receive(:perform_async_in_queue) .with(email.id, queue: :send_email_immediate_high) expect { Rake::Task["support:resend_failed_emails:by_id"].invoke(email.id.to_s) } @@ -67,7 +67,7 @@ end it "updates the failed emails' status to pending" do - allow(SendEmailWorker).to receive(:perform_async_in_queue) + allow(SendEmailJob).to receive(:perform_async_in_queue) email = create :email, status: :failed @@ -89,7 +89,7 @@ it "queues specified failed emails to resend" do email = create :email, status: :failed - expect(SendEmailWorker).to receive(:perform_async_in_queue) + expect(SendEmailJob).to receive(:perform_async_in_queue) .with(email.id, queue: :send_email_immediate_high) expect { Rake::Task["support:resend_failed_emails:by_date"].invoke(from, to) } @@ -97,7 +97,7 @@ end it "updates the failed emails' status to pending" do - allow(SendEmailWorker).to receive(:perform_async_in_queue) + allow(SendEmailJob).to receive(:perform_async_in_queue) email = create :email, status: :failed diff --git a/spec/services/bulk_unsubscribe_list_service_spec.rb b/spec/services/bulk_unsubscribe_list_service_spec.rb index c403aa178..841a6f673 100644 --- a/spec/services/bulk_unsubscribe_list_service_spec.rb +++ b/spec/services/bulk_unsubscribe_list_service_spec.rb @@ -7,7 +7,7 @@ let(:govuk_request_id) { SecureRandom.uuid } it "queues a job" do - expect(BulkUnsubscribeListWorker).to receive(:perform_async) + expect(BulkUnsubscribeListJob).to receive(:perform_async) described_class.call(subscriber_list:, params:, govuk_request_id:) end diff --git a/spec/services/content_change_handler_service_spec.rb b/spec/services/content_change_handler_service_spec.rb index b7a44308a..d0060912b 100644 --- a/spec/services/content_change_handler_service_spec.rb +++ b/spec/services/content_change_handler_service_spec.rb @@ -95,7 +95,7 @@ it "enqueues the content change to be processed by the subscription content worker" do allow(ContentChange).to receive(:create!).and_return(content_change) - expect(ProcessContentChangeWorker) + expect(ProcessContentChangeJob) .to receive(:perform_async) .with(content_change.id) diff --git a/spec/services/digest_initiator_service_spec.rb b/spec/services/digest_initiator_service_spec.rb index aeeeab4be..6ceebb463 100644 --- a/spec/services/digest_initiator_service_spec.rb +++ b/spec/services/digest_initiator_service_spec.rb @@ -9,7 +9,7 @@ before do allow(DigestRunSubscriberQuery).to receive(:call).and_return(subscribers) - allow(DigestEmailGenerationWorker).to receive(:perform_async) + allow(DigestEmailGenerationJob).to receive(:perform_async) end context "when a digest run isn't processed" do @@ -35,11 +35,11 @@ .to(true) end - it "enqueues DigestEmailGenerationWorker for each DigestRunSubscriber" do + it "enqueues DigestEmailGenerationJob for each DigestRunSubscriber" do described_class.call(date: Date.current, range: Frequency::DAILY) ids = DigestRunSubscriber.last(2).pluck(:id) - expect(DigestEmailGenerationWorker).to have_received(:perform_async).with(ids[0]) - expect(DigestEmailGenerationWorker).to have_received(:perform_async).with(ids[1]) + expect(DigestEmailGenerationJob).to have_received(:perform_async).with(ids[0]) + expect(DigestEmailGenerationJob).to have_received(:perform_async).with(ids[1]) end it "can resume a partially processed digest run" do diff --git a/spec/services/immediate_email_generation_service_spec.rb b/spec/services/immediate_email_generation_service_spec.rb index 4c142d2b9..31b24381d 100644 --- a/spec/services/immediate_email_generation_service_spec.rb +++ b/spec/services/immediate_email_generation_service_spec.rb @@ -7,7 +7,7 @@ create(:matched_content_change, subscriber_list:, content_change:) - allow(SendEmailWorker).to receive(:perform_async_in_queue) + allow(SendEmailJob).to receive(:perform_async_in_queue) end it "generates emails for active, immediate subscribers" do @@ -26,24 +26,24 @@ .not_to(change { Email.count }) end - it "queues SendEmailWorkers" do + it "queues SendEmailJobs" do create(:subscription, subscriber_list:) described_class.call(content_change) email_ids = Email.order(created_at: :desc).pluck(:id) - expect(SendEmailWorker) + expect(SendEmailJob) .to have_received(:perform_async_in_queue) .with(email_ids.first, an_instance_of(Hash), queue: :send_email_immediate) end - it "sets metrics for the SendEmailWorker" do + it "sets metrics for the SendEmailJob" do create(:subscription, subscriber_list:) metrics = { "content_change_created_at" => content_change.created_at.iso8601 } described_class.call(content_change) - expect(SendEmailWorker) + expect(SendEmailJob) .to have_received(:perform_async_in_queue) .with(an_instance_of(String), metrics, an_instance_of(Hash)) end @@ -55,7 +55,7 @@ create(:subscription, :immediately, subscriber_list:) described_class.call(content_change) - expect(SendEmailWorker) + expect(SendEmailJob) .to have_received(:perform_async_in_queue) .with(Email.last.id, an_instance_of(Hash), queue: :send_email_immediate_high) end @@ -75,7 +75,7 @@ it "can create and queue emails" do expect { described_class.call(message) } .to change { Email.count }.by(1) - expect(SendEmailWorker) + expect(SendEmailJob) .to have_received(:perform_async_in_queue) .with(Email.last.id, an_instance_of(Hash), queue: :send_email_immediate) end @@ -83,7 +83,7 @@ it "doesn't set any metrics" do described_class.call(message) metrics = {} - expect(SendEmailWorker) + expect(SendEmailJob) .to have_received(:perform_async_in_queue) .with(an_instance_of(String), metrics, an_instance_of(Hash)) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 83f4974b1..e4599a3b2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -36,7 +36,7 @@ config.include ActiveSupport::Testing::TimeHelpers config.before(:each) do - Sidekiq::Worker.clear_all + Sidekiq::Job.clear_all end config.after type: :request do @@ -58,7 +58,7 @@ WebMock.disable_net_connect!(allow_localhost: true) Sidekiq::Testing.inline! -Sidekiq::Worker.clear_all +Sidekiq::Job.clear_all Sidekiq.configure_client do |config| config.logger = nil end diff --git a/spec/workers/metrics_collection_worker_spec.rb b/spec/workers/metrics_collection_worker_spec.rb deleted file mode 100644 index e34ad3da1..000000000 --- a/spec/workers/metrics_collection_worker_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -RSpec.describe MetricsCollectionWorker do - describe ".perform" do - it "delegates to collect metrics" do - expect(MetricsCollectionWorker::ContentChangeExporter).to receive(:call) - expect(MetricsCollectionWorker::DigestRunExporter).to receive(:call) - expect(MetricsCollectionWorker::MessageExporter).to receive(:call) - - subject.perform - end - end -end diff --git a/spec/workers/recover_lost_jobs_worker_spec.rb b/spec/workers/recover_lost_jobs_worker_spec.rb deleted file mode 100644 index 89c2dc1b3..000000000 --- a/spec/workers/recover_lost_jobs_worker_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -RSpec.describe RecoverLostJobsWorker do - describe "#perform" do - it "delegates recovery" do - expect_any_instance_of(RecoverLostJobsWorker::UnprocessedCheck).to receive(:call) - expect_any_instance_of(RecoverLostJobsWorker::MissingDigestRunsCheck).to receive(:call) - expect_any_instance_of(RecoverLostJobsWorker::OldPendingEmailsCheck).to receive(:call) - - subject.perform - end - end -end