Closed sehmaschine closed 3 years ago
Hello! All Repeater does is make an HTTP(S) call to a URL at a given point in time and then record the response. It can make that call once, or repeatedly (ha!) at a set interval.
It's also tailored for the Jamstack where you'll generally expose your app's functionality as API calls somewhere. In Jamstack land this has generally been through AWS Lambda functions. When you deploy to lambda you get a URL that you can access to invoke your function.
So in usecase (1) you might have the code that sends an email, or starts a backup, exposed at some endpoint. Repeater would then call that endpoint at the specified time. You can then later query Repeater and ask for the response of that call (or ignore it completely for non-critical jobs).
Now, depending on your email service and its own API, you may be able to have Repeater call the third party service directly and skip your app entirely—SendGrid will send an email by just POSTing to an endpoint. But personally, I'd want to keep the code for sending the email within my app and just expose the "send an email now" functionality as an API call, and just have Repeater call that endpoint for me. That call can contain security information to make sure that bad actors can't find the endpoint and send billions of emails a second (you can set query params and headers in the Repeater call).
Usecase (2) is totally doable, but you may need some creative architecture. Here's two ways I can think of to do what you're looking for:
But remember: Repeater itself doesn't perform any logic or execute any packaged up code for you—all it does is call a URL and record the result. Whatever URL it calls will be where the magic actually happens.
Does that help?
Thanks for the explanation. I'm coming from Celery/RabbitMQ and would like to find a more lightweight solution for usecase 2.
What I had in mind is this:
Does that sound reasonable?
Additional question: I'm not exactly sure about the database flag in order to indicate that the job has finished. I would like to avoid adding flags for the state of every background process with my DB. Do you really think that´s necessary given the workflow described above? Isn't it exactly the point of using something like Repeater in order to check for finished jobs? Or do I miss something here?
Yep that flow makes sense to me!
The benefit of the database flag is that you can (probably) query your own servers and get a response faster than the query to Repeater. And any server-side code can access that flag directly, instead of through a GraphQL call out to Repeater. But we're talking like a 50-100ms difference, which may not matter at all for what you're doing.
There's another solution out there if you find that Repeater isn't exactly what you're looking for: https://quirrel.dev/ It sort of abstracts away the fact that the processing is happening on another system altogether, and it looks like it'll actually process arbitrary JS code, not just call a URL. I'm not sure from the code samples if you can check on the status of jobs at all, or rerun/change them in any way, but you may not need that functionality. It also doesn't provide any kind of UI that I can see, whereas Repeater has a whole dashboard for monitoring jobs/results.
Thanks. I'm fine with just calling a URL, so Repeater will probably work for our usecase. Feel free to close this issue.
We have different kinds of background tasks with our appliations:
My question is if repeater also covers usecase 2 or if it is mainly developed to solve usecase 1. When looking at the docs, it seems that both usecases are currently covered. I'm just curious about the general direction/philosophy of repeater. Because we would like to stick with the chosen solution for a while ...