-
Notifications
You must be signed in to change notification settings - Fork 293
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
Add email worker and send email support #624
base: main
Are you sure you want to change the base?
Conversation
15deda7
to
d639b16
Compare
75e3e45
to
a72c76b
Compare
a72c76b
to
c712ffd
Compare
|
||
// For some reason, email events doesn't seem to use WorkerEntrypoint so we get the env and ctx from | ||
// from the function itself. | ||
async email(message, _env, _ctx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ObsidianMinor do you know why email worker wouldn't use the new interface? Will cron triggers have the same issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still haven't figured it out yet - for some reason env
is still not probably propagated into the rust layer, and therefore I can't seem to use bindings with it 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its also quite difficult to debug because email workers can't be run locally 😅
|
||
// TODO(lduarte): see if also accepting string is needed | ||
#[wasm_bindgen(constructor, catch)] | ||
pub fn new(from: &str, to: &str, raw: &str) -> Result<EmailMessage, JsValue>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also have a new_from_stream
method that takes ReadableStream
?
} | ||
|
||
#[wasm_bindgen] | ||
extern "C" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add headers
field? Should these getters also be on EmailMessage
?
pub fn forward( | ||
this: &ForwardableEmailMessage, | ||
rcpt_to: &str, | ||
headers: Headers, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field should probably be optional, or maybe have forward
and forward_with_headers
. Or is there no difference between headers
being undefined
or {}
in JavaScript API?
use wasm_bindgen::JsCast; | ||
use wasm_bindgen::JsValue; | ||
use wasm_bindgen_futures::JsFuture; | ||
use worker_sys::EmailMessage as EmailMessageExt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would typically call this EmailMessageSys
.
} | ||
|
||
pub async fn reply(&self, message: EmailMessage) -> Result<(), JsValue> { | ||
JsFuture::from(self.0.reply(message.0)?).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to wrap these async calls as follows, otherwise the method's Future will not be Send:
let promise = self.0.reply(message.0)?;
let fut = SendFuture::new(JsFuture::from(promise));
fut.await?;
Basically, you don't want to hold JsFuture
across await
boundary.
unsafe impl Send for EmailMessage {} | ||
unsafe impl Sync for EmailMessage {} | ||
|
||
impl JsCast for EmailMessage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be wrong, but you may not need all of this boilerplate for types that do not need to implement EnvBinding
.
Closes #274
Adds Email Worker support in workers-rs in addition to Send Email support