Skip to content

Commit

Permalink
Further decompose reminders service helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
akabiru committed Dec 2, 2024
1 parent d65b624 commit 4bb7007
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
11 changes: 11 additions & 0 deletions app/services/concerns/reminders/service_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions app/services/reminders/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions app/services/reminders/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4bb7007

Please sign in to comment.