Beach supports user-defined cron job scripts for selected instance types. Cron jobs are run every hour. If you'd like to run a script only at specific times, for example every night at 3:00 am, you can do so by adding a simple condition to your script.

The Details

Simply create a file called beach-cron-hourly.sh, commit it to your project's root directory and deploy it.

The following script actually contains two jobs:

  • the first job is run every first of the month after midnight and ends a "settlement period" for billing
  • the second job is run every day at 10pm and registers some storage logs

CURRENT_DATE=`date +"%Y-%m-%d"`
CURRENT_DATE_ALT=`date +"%y-%m-%d"`
CURRENT_TIME=`date +"%H:%M:%S"`
CURRENT_DAY=`date +"%d"`
CURRENT_HOUR=`date +"%H"`
YESTERDAY_DATE=`date -ud"${CURRENT_DATE} -1 days" +"%d.%m.%Y"`

if [ "${CURRENT_DAY}" == "01" ] && [ "${CURRENT_HOUR}" == "00" ] ; then
    echo "${CURRENT_DATE_ALT} ${CURRENT_TIME}          INFO        Beach Cron Job       Ending settlement period per ${YESTERDAY_DATE}" >> /application/Data/Logs/System.log
    /application/flow billing:endsettlementperiod --cutoffDate ${YESTERDAY_DATE}

if [ "${CURRENT_HOUR}" == "22" ] ; then
    echo "${CURRENT_DATE_ALT} ${CURRENT_TIME}          INFO        Beach Cron Job       Queuing registration of storage logs of instance buckets" >> /application/Data/Logs/System.log
    /application/flow storage:registerstoragelogs

Your cron job script will be invoked every hour. However, it's not always sure at which minute that is. Most of the time it will be run a quarter past the full hour – but don't rely on it.

Keep in mind that if you deploy your instance right at the time the cron job will happen, your script might be interrupted or never called at all. It's only a very short timeframe, and therefore unlikely to happen, but better be prepared.