Run jobs on the clock with cron on BrewInTH, and hear when they fail

Run scheduled jobs at an exact Thai time with five cron fields, with examples, and see how BrewInTH tells you when a job fails three times in a row.
You want yesterday's sales summary in your inbox every morning at 8. You set the job to Every day on the Schedules tab, and it runs at 2 in the afternoon instead, because that's when you pressed the button. Then one day the script breaks, and nobody notices until a customer asks.
This guide shows how to run a job at an exact Thai time with the At a time of day (cron, Thai time) option, how to read and write the five cron fields (with examples to copy), how BrewInTH tells you when a job keeps failing, and what to ask your AI for so the platform can read each run's result.
In short
🕗 Pick At a time of day (cron, Thai time) and enter0 8 * * *: the job runs at 08:00 Thai time every day, whenever you added it
🧮 The five cron fields are minute, hour, day of the month, month and day of the week;*means every value
🔔 After three failures in a row, the account owner gets an e-mail and the console shows a red banner
🧾 The Schedules tab shows how many runs failed in a row, since when, and the last two lines the job printed
✅ A schedule belongs to the project: it keeps running after the token of the AI that created it expires
Why "Every day" doesn't run when you want
The frequencies from Every 5 minutes to Every week count from the moment you press Add schedule. Add an Every day job at 14:20 and it first runs tomorrow at 14:20, then at that time every day after. Pressing Run now on such a job restarts the count from that moment.
At a time of day (cron, Thai time) ties the job to the clock instead. Enter 0 8 * * * and it runs at 08:00 Thai time every day, no matter when you added it, and Run now tests it without moving the regular time. The platform looks for due jobs every minute, so a job starts in its minute or shortly after.
If you followed older advice to press Run now at 3 a.m. to set the time, or to run a job every 5 minutes and let the script check the Thai time, you can stop.
How to read the five cron fields
cron is the short way of writing times that almost every scheduler understands: five fields separated by spaces, read from left to right.
- Minute, 0–59
- Hour, 0–23 on a 24-hour clock
- Day of the month, 1–31
- Month, 1–12 or jan–dec
- Day of the week, 0–6 where 0 is Sunday (7 counts as Sunday too), or sun–sat
Each field takes these symbols: * for every value, , for a list such as 0,30, - for a range such as 1-5, and / for "every so many": */15 in the minute field means every 15 minutes.

Common examples, all in Thai time:
0 2 * * *02:00 every day, good for heavy work while few people use the site0 8 * * *08:00 every day30 8 * * 1-508:30 Monday to Friday0 9 * * 109:00 every Monday0 7 1 * *07:00 on the 1st of every month0 */6 * * *every 6 hours, at 00:00, 06:00, 12:00 and 18:00*/15 9-17 * * *every 15 minutes from 09:00 to 17:45
Three things to know about cron on BrewInTH:
- There's no seconds field, and shortcuts such as
@dailyorL(the last day of the month) aren't accepted. - When you give both a day of the month and a day of the week, the job runs when either one matches:
0 9 1 * 1runs on the 1st and on every Monday. - A job set for the 31st runs only in months that have one.
Set a job to run on time, step by step
1. Have your AI write the job as a script that ends
A scheduled job is a command that runs and then finishes, not a program that stays open. The message for your AI is in "Ask your AI for a script the platform can read" below. If you've never used this tab, start with the basics of scheduled jobs.
2. Add it on the Schedules tab
Open the project and go to the Schedules tab. Only app projects have it; static sites don't.
- Name: English letters, numbers and hyphens, such as
daily-summary. Thai names with vowel or tone marks above or below the line are refused with "Please check the form fields". - Command: for example
node scripts/daily-summary.js. - Frequency: choose At a time of day (cron, Thai time). A Time (5 cron fields: minute hour day month weekday) field appears with
0 2 * * *in it; change it to the time you want. - Timeout per run (seconds): 120 by default, up to 14,400 (4 hours). Leave a margin over how long the job really takes, because a run that goes over is stopped and counts as a failure.
- Press Add schedule.

If the cron isn't in a valid form, the job isn't added and a red message appears under the form, such as "Request failed: cron_invalid". Check that there are five fields separated by spaces.
3. Check the time in the table, then press Run now
The new job appears in the table below the form. Every shows the cron with its time zone, Asia/Bangkok, and Next run shows the date and time by the clock of the device you're viewing it on. Add 0 8 * * * in the afternoon and it should say 08:00 tomorrow.
Then press Run now once to test it. The platform runs it at its next check, and Last run then shows Succeeded, or Failed with the code the command ended with. A long job may show Needs configuration with "Waiting for sandbox command completion" while it runs. That means it's still running, not that it failed.
How BrewInTH tells you a job keeps failing
A run counts as failed when the command ends with a code other than 0, runs past its Timeout per run, or is stopped for using more memory or /tmp space than the package allows. When the platform stopped the run, a line starting with [hint] says why.

From the first failure, the Schedules tab shows Failed in a row with the count, since when, and the last two lines the job printed. After three failures in a row, you hear about it in two more ways:
- An e-mail to the account owner, with a subject like
[brewInTH] Schedule "daily-summary" of Manee Bakery failed 3 times in a rowfor an account in English. It carries the job's last output and a link to the project, and it's sent once per run of failures, at most once a day per job. - A red banner in the console: on the Overview with the project and job names, and on the project page with an Open the Schedules tab button.
Meanwhile the job keeps running at its times; the platform doesn't pause it for you. If you can't fix it yet, press Pause, which stops the runs, the banner and the e-mail. Once a run succeeds, the count starts over and the banner goes away by itself.
The e-mail goes to Report / alert email in Account settings. If that's empty, it goes to your verified recovery e-mail. With neither, the Schedules tab says "not e-mailed: the account has no e-mail address", and the banner in the console is all you get.
Mind the timing, too. A job that runs every 5 minutes fails three times in about 10 minutes, but a daily job takes three days to get there. For a daily job that matters, look at the tab the morning after you set it up, or have the script message you itself the first time it fails.
Ask your AI for a script the platform can read
The platform decides whether a run succeeded from the code the command ends with, and shows its last two lines in the tab and the e-mail. A script that catches its own errors and then ends normally is never counted as failed. Send your AI this message and adjust the details to your site:
Please write a "yesterday's sales summary" job that e-mails owner@maneebakery.com, to run as a BrewInTH schedule every day at 08:00 Thai time.
- Make it a separate script, scripts/daily-summary.js, that runs and exits. Don't use node-cron or any timer inside the app.
- Work out "yesterday" in the Asia/Bangkok time zone in the code; don't rely on the machine's time zone.
- On success, print one short summary line such as "Sent the summary of 42 orders" and exit 0.
- On failure, print the reason as the last line and exit 1. Never print passwords, tokens or customer data.
- Running it twice on the same day must not send a second e-mail.
- The whole job must finish within 5 minutes.
Then publish again, test the script once, and create the schedule with cron "0 8 * * *" in the Asia/Bangkok time zone.
Why each line is there:
- The time zone in the code: the schedule's cron uses Thai time, but the platform doesn't set Thai time inside your app. The clock your code reads may be UTC, 7 hours behind Thailand, so "yesterday" worked out at 08:00 could be the wrong day.
- Exit 1 on failure lets the platform count the failure and tell you.
- A last line that gives the reason, with no secrets, because that's the text that shows in the tab and the e-mail.
- Running twice doesn't send twice, so pressing Run now to test never sends two e-mails.
The last line asks the AI to create the schedule itself, which needs the Run app commands, including migrations permission. If your AI doesn't have it, drop that line and add the job yourself as above.
If the work already lives in a page of your app, such as /api/cron/daily, tell your AI: "Have the script call that page at the address in the APP_INTERNAL_URL variable, and exit 1 if the page doesn't answer with success." A scheduled job reaches its own app at that address without going out to the internet.
Before you rely on scheduled jobs
- A job runs from the published version. After changing the script, publish again; the next run uses the new code.
- Missed runs aren't made up. If a run comes due while the project is paused, or before it has a running version, the platform skips it and waits for the next one.
- A new run doesn't wait for the last one. If one run takes longer than the gap between runs, the next starts while the last is still going. Space the runs out, or have the script guard against overlapping.
- A schedule belongs to the project, not the token. A job an AI created keeps running after its token expires or is revoked; delete it on this tab if you no longer want it.
- A PHP site can send e-mail from a scheduled job with mail(), just like its pages, once a mailbox is connected to the app (make PHP mail work).
FAQ
Can I change the time of an existing job?
The console only lets you change the command, with Edit command. To change the time, add a new job with the time you want and delete the old one; the old job's history goes with it. A project can have up to 10 jobs.
Can a job run on the last day of the month?
Not directly, because cron on BrewInTH doesn't take L. Set 0 23 28-31 * * and have the script check whether tomorrow is the 1st; if it isn't, the script just exits 0.
Can I use another time zone?
The console always uses Thai time (Asia/Bangkok). For another zone, such as Asia/Tokyo, have an AI with the permission to run app commands create the job with that zone.
Next run doesn't show the time I set. Why?
That column shows times by the clock of the device you're viewing it on. If your computer is set to another time zone, the time looks different, but the job still runs at the Thai time in its cron.
Does a job run while my site is asleep?
Yes. A scheduled job doesn't wait for the app to wake up. While the app is asleep, though, a command that calls the app through APP_INTERNAL_URL won't get through, because the job doesn't wake it. A project you paused yourself runs no jobs at all (sleeping free sites).
I got the failure e-mail. What now?
Follow the link to the Schedules tab and copy the command and its last two lines to your AI so it can fix the cause (how to report an error to your AI). Publish again, then press Run now to see it succeed. If you can't fix it yet, press Pause.
Summary
For a job that has to run on time, choose At a time of day (cron, Thai time), enter the five cron fields, check Next run, and press Run now once to test. Have the script exit 1 with a reason when it fails, and the platform tells you by e-mail and with a red banner after three failures in a row. Remember to fill in Report / alert email in Account settings. The in-console guide shows the real screens of this tab.
