rails-letsencrypt
rails-letsencrypt copied to clipboard
Implement ActiveSupport notifications
Is there a recommend way of getting notified of failed renewals? I see that https://github.com/elct9620/rails-letsencrypt/blob/master/lib/tasks/letsencrypt_tasks.rake#L15 just puts out "Could not renew domain". What do you think of implementing ActiveSupport notifications here? Then a developer could subscribe to the event and handle this case (for example alert the admin or remove the domain). Or any alternative way to listen to such events?
I think ActiveSupport notification is a good idea, but we may need to consider to it is running inside the Rake task. The notification may not be correctly subscribed. I think we can add ActiveJob support as a scheduler job.
Should not be a problem running in a rake task, it is already in the Rails env.
I think just adding ActiveSupport::Notifications.instrument
either in the model (certificate.renew) or related concern should do the trick. But I have not looked at the code too closely to say where it is most appropriate to trigger any event for error/status.
Let's add this feature before the next release.
Or is there any alternative way of handling it? The goal here is to be able to handle renewal failures. One option is to just copy the rake task and modify it to handle failures. Another option is for renew
to raise an error when not succeeding.
We need some refactoring for it. However in the first phase to make it available, I plan to put some hook when Certificate#renew
is called so that we can subscribe to it.
For example:
def renew
ActiveSupport::Notifications.instrument('letsencrypt.renew', domain: domain) do
verify && issue
end
end
ActiveSupport::Notifications.subscribe('letsencrypt.renew') do |*args|
# filter by args.payload[:exception]
end