Cron Jobs
A Deta Micro can be set to run on a schedule from the deta cli
using the deta cron set command.
In this guide we are going to configure a deta micro to run every five minutes.
The guide assumes you have already signed up for Deta and have the Deta CLI installed.
- JavaScript
- Python
Create a directory
cron-job
and change the current directory to it.In order to set a micro to run on a schedule, the micro's code needs to define a function that will be run on the schedule with the help of our library
deta
, which is pre-installed on a micro and can just be imported directly.Create a
index.js
file and define the function that should run on the schedule.Create a new
nodejs
micro withdeta new
.Even though the output shows a HTTP endpoint, you do not need it for cron.
Set the micro to run on a schedule with the deta cron set command.
We have set the micro to run every five minutes. In order to see if a micro is running on a schedule, you can use the
deta details
command.The details show that the
cron
has ben set for5 minutes
In order to see logs of your cron-job, you can use
Deta Visor
, which enables you to see real-time logs of a Deta Micro. Open your micro's visor page withdeta visor open
from the cli or by navigating to your micro's visor page on the browser.
We have a micro which prints "running on a schedule" every five minutes. You should see the execution logs in your micro's visor page every five minutes.
Create a directory
cron-job
and change the current directory to it.In order to set a micro to run on a schedule, the micro's code needs to define a function that will be run on the schedule with the help of our library
deta
, which is pre-installed on a micro and can just be imported directly.Create a
main.py
file and define the function that should run on the schedule.Create a new
python
micro withdeta new
.Even though the output shows a HTTP endpoint, you do not need it for cron.
Set the micro to run on a schedule with deta cron set command.
We have set the micro to run every five minutes. In order to see if a micro is running on a schedule, you can use the
deta details
command.The details show that the
cron
has ben set for5 minutes
In order to see logs of your cron-job, you can use
Deta Visor
, which enables you to see real-time logs of a Deta Micro. Open your micro's visor page withdeta visor open
from the cli or by navigating to your micro's visor page on the browser.
We have successfully deployed a micro which prints "running on a schedule" every five minutes. You should see the execution logs in your micro's visor page every five minutes.
Full documentation on cron is available here.