Recurring Tasks Without 3rd Party Services

Hi everyone!

I’m investigating Redwood for some small and mid-sized projects, both of which need to fill their databases regularly (one is a local network crawler, one caches gitlab information).

For that I would like to use recurring tasks, but I don’t want to setup Celery or Quirrel. Using hosted services is also out of the question since theses projects need to run in a local-only environment.

Two options I would like to try are:

  • Run some code on server startup that starts a background task (that’s what I did in my Blitz.js tests)
  • Create a second entrypoint in the api package that has access to the db as well, but can be put in crontab to be run regularly

I would honestly prefer the first option because it allows me to use sqlite in very small deployments (which wouldn’t work so well when the db needs to be accessed from multiple processes)

I don’t know how to do either of those things in Redwood, and haven’t found any documentation on it yet.

I know Redwood is designed to be run on “serverless” infrastructure and thus running a persistent server on startup is kind of against the design, but it’s more or less necessitated by my usecase (or by the need to be operationally simple), and I really like many other aspects of Redwood.

I’m looking forward to any suggestions :slight_smile:

I believe that you can set an AWS lambda to run on a schedule, then have it call your code

That’s the way I’m intending to handle my regular tasks, so I hope I’m right !!


Have you checked out GitHub Actions? You can run cron jobs right from your repo.

I’m aware of those options, but those are not suitable for my usecase, which should be fully-local. If I wanted an external taskrunner I could do this by running Quirrel or Celery, but this means the people I’m building this for would have to host at least two extra services, taking this from a simple docker deploy to an orchestration problem.

I could also ping my own Function via an http request from crontab, and maybe this will be the solution I will go with, but I would much rather have the ability to do this scheduling completely inside the application. For one because it is simpler to host and have an overview over, but also because I would have to secure the Function against random http request.

As I said, I’m aware that Redwood is designed with the idea of using all of the cloud services, but I design software for private-cloud enterprises (which are running celery, so not that much of a problem there) and people who want to run stuff on their NAS. It might be that Redwood is just not a good fit for that, but I’m hoping otherwise.

I’ve scoured the documentation a bit more, and it seems I might get somewhere with scripts. At least that will give me an entrypoint to call via crontab :slight_smile:

I’ll try modifying the database directly from there, but what would probably also work is calling a webhook from inside the script, using the correct secret.

For your use case, I would create a api endpoint and then run a cronjob to hit that endpoint.

Or use the exec feature to run a script. This can also be run via cronjob via rw exec command.

Both of these options will have access to the DB so you can make your DB updates.