Service Binding in Cloudflare Workers
You probabaly want to use a service bind to make a worker calls itself https://developers.cloudflare.com/workers/configuration/bindings/about-service-bindings/
9 Replies
For the binding do I need to make 2 separate workers?
No, you have can service bindings for the same worker. Though it might be easier to just have your code call the same function as endpoint B
can you share some github gist of it or even any repo
Of service binding to self?
yes. I mean I am not sure about how can I bind a service to self. I tried finding out docs but ended up creating another worker and now it says to add variable name here.
![No description](https://cdn.answeroverflow.com/1214255912836141056/Screenshot_2024-03-04_at_10.29.11_PM.png)
Like I said previously these are 2 endpoints. Now when
/invite
gets triggered I have few ms to send back the response otherwise request would time out.
That is why I've create /mention-each
route. The purpose of it is to do the computing on the behalf of /invite
. But this enpoint should get trigger automatically.![No description](https://cdn.answeroverflow.com/1214256561346584626/Screenshot_2024-03-04_at_10.30.07_PM.png)
I’d recommend responding to the original reaction and using ctx.waitUntil to do the rest of the work. Also means your worker will only have to do one request.
Hello @Cyb3r-Jok3
just wanted you to know that I am now calling the endpoint like this, using waitUntil. The error which I was getting earlier was because of quickly closing a connection. But using watUntil solved the problem.
![No description](https://cdn.answeroverflow.com/1214281865264103554/Screenshot_2024-03-05_at_12.10.20_AM.png)
Update :
instead of making another API call. I've provided the promised version of my actual logic and it is working absolutely fine.
Thanks a lot for helping me out. @Cyb3r-Jok3