Skip to content
ErawanACADEMYไทย

Keep it running

Work that runs on a schedule and how to see how it went

Clearing old data every night, a report every Monday morning, a reminder to customers at 8 pm. Set it up once and it keeps running, with the same code and settings as your app, and no computer of yours left on.

Stuck somewhere? Erawan looks into it for free on Hobby and above.

Tell your AI what to run, and when

Say it in plain words. Your AI turns it into a cron schedule.

Schedule my-app to run python cleanup.py every day at 3 am Thai time.

To set it yourself in a terminal, give the task a name, then the schedule, then the command to run.

erawan task add my-app nightly "0 20 * * *" python cleanup.py

The five cron fields are minute, hour, day of month, month and day of week, so this line runs at 20:00 UTC every day, which is 3 am the next morning in Thailand.

The schedule runs on UTC

Not Thai time, and this is the one people get wrong most. Thailand is seven hours ahead of UTC, so 3 am Thai time is 20:00 UTC the evening before, as in the line above. Write 0 3 * * * by mistake and nothing fails: the task runs every day, at 10 am Thai time instead. When you ask your AI, add “Thai time” every time and it converts for you.

What a task runs with

A task uses the same code as your app and gets all of the same settings, including the database connection and your keys, so there is nothing to set up separately. When you put a new version online, every task moves to the new code with it.

Three limits to know:

  • Each run gets up to 10 minutes and 256MB of memory. A run that goes over is stopped. A failed run is not retried, and the next one comes at its usual time. For heavier work, have your AI split it into smaller pieces.
  • The app's disk is read-only. If the task has to write or delete files on the disk, such as clearing a cache, tell your AI the task needs to write to the disk (in the command, that is --write).
  • It needs an app with a program running. A website made only of files cannot have tasks.

Try it once first

Before you schedule it, have your AI run the command once, now. It uses the same code and settings as the real task, so you find out now whether the command is wrong, not tomorrow morning.

erawan run my-app python cleanup.py

See how the last run went

erawan task ls my-app
erawan task logs my-app nightly

The first lists the app's tasks and when each last ran. The second shows what the last run printed. You can also ask your AI “how did the last nightly run go?” Look once after the first run: a task that fails quietly at 3 am looks, from outside, exactly like a task that was never set up.

Change the time, or remove a task

To change the time, set the task again under the same name, and the new one replaces the old. When you no longer need it, remove it.

erawan task rm my-app nightly

Deleting the app deletes its tasks with it, so no schedule is left running against an app that is gone.

If you want a task to send its report by email, the next step is sending email from your app.

All Erawan Cloud lessons