In this article, we will create a very simple cron job called "echo". It will just print a value of an environment variable set by injecting a secret, and the lines printed by the cron job will be registered in the logs and can later be viewed there.
In the project navigation menu, click on "Cron Jobs".
In the cron job manager, click on "New Cron Job".
Then scroll down to fill other fields described in the next subsection.
*/2 * * * *
.Then scroll down to fill other fields described in the next subsection.
Here we can specify the command that will be passed to the container in which our cron job will run. In this example, we will use the command sh -c 'echo DB_NAME: $DB_NAME'
, which will print the environment variable $DB_NAME
from the "database-live" secret we specified before.
Each argument of the command must be in a separate field. Use the "+" button to create as many fields as there will be arguments.
Create 3 fields using the "+" button and enter the 3 command arguments:
sh
-c
echo DB_NAME: $DB_NAME
Then scroll down to fill other fields described in the next subsection.
Now we can see our newly created cron job in the list of cron jobs.
After some time, click on the "Logs" button to see the output of the cron job. In the Logs window that will open, you should see the output of the "echo" command, assuming that the DB_NAME variable in our secret is equal to "namekpznnqjckw":
DB_NAME: namekpznnqjckw
This message will be repeated every two minutes.
If runnning the cronjob is no longer required, use the "Disable" or "Delete" buttons shown on the screenshot above.