Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ActiveSupport notifications #33

Open
espen opened this issue Mar 4, 2022 · 5 comments
Open

Implement ActiveSupport notifications #33

espen opened this issue Mar 4, 2022 · 5 comments

Comments

@espen
Copy link
Contributor

espen commented Mar 4, 2022

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?

@elct9620
Copy link
Owner

elct9620 commented Mar 4, 2022

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.

@espen
Copy link
Contributor Author

espen commented Mar 7, 2022

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.

@elct9620
Copy link
Owner

elct9620 commented Nov 7, 2023

Let's add this feature before the next release.

@espen
Copy link
Contributor Author

espen commented Nov 7, 2023

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.

@elct9620
Copy link
Owner

elct9620 commented Nov 7, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants