Should cron jobs and apis be in separate workspaces?

Hello,

I am new to rust, so bare with me.

I am working on a Rust service that has 2 functionalities:
1- Host Apis
2- Periodically fetch data from a certain endpoint and store in the DB
I am thinking should these be considered mico-services? Should they live in separate work-space?

If they share the same database, I wouldn't split them. You can perfectly have a cronjob as part of the same app, just start the app differently depending on some arguments passed during startup.

Generally you did use a single workspace for a whole project. Note that there is no technical reason for this. It just enables reusing the same Cargo.lock and target directory. It also males it easier to build or test the whole project.

1 Like

I suggest having the thing that you want to run periodically also be an API. That's way better for testability.

Then you can use some existing "call an endpoint on a schedule" service to invoke it, rather than writing that yourself. A quick search found Cloud Scheduler  |  Google Cloud and Timer trigger for Azure Functions | Microsoft Learn , but I assume whatever platform you use has something for this.

Thats a great suggestion I will look into that!

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.