swoosh
swoosh copied to clipboard
Terminate/cancel the currently sending email
Is your feature request related to a problem? Please describe.
I need to cancel the delivering process of the email when a timeout is reached. I would like handle by myself when the request should be cancelled
Is your feature request related to a specific adapter? Please specify.
Gmail, but could apply to others as well
Describe the solution you'd like
It could be implemented in various ways, and this one is not the smartest one:
The deliver
function can receive a worker PID and would listen to its internal messages and in case there would appear something like :terminate
it would cancel the request (email deliver) and exit with a corresponding status atom
Describe alternatives you've considered
probably a configurable timeout in deliver/2
config argument, I could not clearly find in the docs what config
is supposed to have, probably just some adapters specific configuration, would be nice to have some Finch
configs too, in case it implements those timeout/request cancellations already
Additional context
email |> put_private(:client_options, options)
will be passed to your http client.
Hi @princemaple and big thanks for a quick reply, yeah the put_private\3
solved it, but I could not find in the docs all available keys that are available for configuration.
I assume there are more than just :client_options
I would possibly use 😄
Thanks 🙏
There are actually not that many. This one is documented on the Email module. And provider specific options are documented on respective provider module.
That's all I can recall at the moment.
Ohh, I see. But back to my question, passing a timeout to client API (Finch
in my case) would not support cancellable requests, I see in the implementation is used Finch.request
that internally does not support cancellable requests and only the Finch.stream
might work in this case https://github.com/sneako/finch/issues/112.
I can receive the right timeout error now from Finch, but the email is still delivered, which is not desired
Hmm. I don't know. I may accept PR about this, but I don't think I'll go and implement it, as it's going to be hard to keep hackney and SMTP up to speed.
I would say that, if you want to cancel it in general, run it inside a task and then send a shutdown/kill signal to the task to terminate it. I don't think swoosh in particular needs to accommodate it. :)