From 4bb700718c67f3fda377f13bfed4cdc575ee5f18 Mon Sep 17 00:00:00 2001 From: Kabiru Mwenja Date: Mon, 2 Dec 2024 16:59:45 +0300 Subject: [PATCH] Further decompose reminders service helpers --- app/services/concerns/reminders/service_helpers.rb | 11 +++++++++++ app/services/reminders/create_service.rb | 6 +++--- app/services/reminders/update_service.rb | 10 +--------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/services/concerns/reminders/service_helpers.rb b/app/services/concerns/reminders/service_helpers.rb index 0865cbfd4152..b6e27e2d446a 100644 --- a/app/services/concerns/reminders/service_helpers.rb +++ b/app/services/concerns/reminders/service_helpers.rb @@ -30,6 +30,17 @@ module Reminders module ServiceHelpers extend ActiveSupport::Concern + def reschedule_reminder(reminder) + destroy_scheduled_reminder_job(reminder) + mark_unread_notifications_as_read_for(reminder) + schedule_new_reminder_job(reminder) + end + + def schedule_new_reminder_job(reminder) + job = Reminders::ScheduleReminderJob.schedule(reminder) + reminder.update_columns(job_id: job.job_id) + end + def destroy_scheduled_reminder_job(reminder) return unless reminder.scheduled? return unless job = GoodJob::Job.find_by(id: reminder.job_id) diff --git a/app/services/reminders/create_service.rb b/app/services/reminders/create_service.rb index c5108c749adc..340f980a289f 100644 --- a/app/services/reminders/create_service.rb +++ b/app/services/reminders/create_service.rb @@ -28,10 +28,10 @@ module Reminders class CreateService < ::BaseServices::Create + include Reminders::ServiceHelpers + def after_perform(service_call) - reminder = service_call.result - job = Reminders::ScheduleReminderJob.schedule(reminder) - reminder.update_columns(job_id: job.job_id) + schedule_new_reminder_job(service_call.result) service_call end diff --git a/app/services/reminders/update_service.rb b/app/services/reminders/update_service.rb index b18795f96c50..9a1bd002e1cd 100644 --- a/app/services/reminders/update_service.rb +++ b/app/services/reminders/update_service.rb @@ -31,15 +31,7 @@ class UpdateService < ::BaseServices::Update include Reminders::ServiceHelpers def after_perform(service_call) - reminder = service_call.result - - if remind_at_changed? - destroy_scheduled_reminder_job(reminder) - mark_unread_notifications_as_read_for(reminder) - - job = Reminders::ScheduleReminderJob.schedule(reminder) - reminder.update_columns(job_id: job.job_id) - end + reschedule_reminder(service_call.result) if remind_at_changed? service_call end