# Cron jobs

Run your code on a schedule, all day, on your phone. A page shows when each job runs next and how its last run went.

## Get it

```sh
$ dukoi init cron-jobs
```

It makes a `cron-jobs` folder and deploys it. On the phone instead: **Try a template → Cron jobs → Deploy**.

## What you get

Two jobs to start: one lists new posts on the Hacker News front page every 15 minutes, and one checks the phone’s free space every hour. Runs are kept in `DATA_DIR`.

192.168.0.112:3007

New posts on Hacker News \*/15 \* \* \* \*

Worked 2 min ago, took 412 ms

```
2 new on the front page
  Show HN: I run my side projects on an old Pixel
  The quiet comeback of SQLite
```

## Make it yours

Six files. You only need to touch one.

- `jobs.js`: The jobs and when they run. Edit this one.
- `schedule.js`: Reads cron schedules
- `server.js`: Runs jobs on time and serves the page
- `public/index.html`: The jobs page
- `package.json`: Its name and packages
- `README.md`: How to run it, in five minutes

Add a job to the list in `jobs.js`. What `run()` returns shows on the page:

```
{
  name: 'Say good morning',
  schedule: '0 8 * * *',
  async run() {
    return 'Good morning'
  },
},
```

```sh
$ dukoi deploy
```

A schedule is cron’s five parts: minute, hour, day of month, month and day of week. `*/15 * * * *` is every 15 minutes, `0 9 * * 1-5` is 09:00 on weekdays, and `@hourly`, `@daily`, `@weekly` and `@monthly` work too. Times use the phone’s time zone.
