feat(ntfy): add SendNtfyNotificationJob for async dispatch with retry
This commit is contained in:
23
app/jobs/send_ntfy_notification_job.rb
Normal file
23
app/jobs/send_ntfy_notification_job.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
require "my_smsa_pio/notifications/ntfy/publisher"
|
||||
|
||||
class SendNtfyNotificationJob < ApplicationJob
|
||||
queue_as :notifications
|
||||
retry_on StandardError, wait: :exponentially_longer, attempts: 3
|
||||
|
||||
def perform(admin_id, event_type, title:, message:, priority: 3, tags: [], click: nil)
|
||||
admin = AdminUser.find_by(id: admin_id)
|
||||
return unless admin
|
||||
return unless admin.ntfy_configured?
|
||||
|
||||
MySmsaPio::Notifications::Ntfy::Publisher.new(admin).publish(
|
||||
title: title,
|
||||
message: message,
|
||||
priority: priority,
|
||||
tags: tags,
|
||||
click: click
|
||||
)
|
||||
rescue StandardError => e
|
||||
Rails.logger.error("SendNtfyNotificationJob failed for admin #{admin_id}: #{e.message}")
|
||||
raise
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user