Cronicle icon indicating copy to clipboard operation
Cronicle copied to clipboard

Run job every X months?

Open dsturgilljr opened this issue 2 years ago • 2 comments

In cron, 0 0 1 */7 * would translate to “At 00:00 on day-of-month 1 in every 7th month.”

Is there a solution for converting step values (i.e. */7) to an Event Timing object?

dsturgilljr avatar May 13 '22 14:05 dsturgilljr

I don't think there's a way to get what you want here. Cronicle does have a feature in the UI where it can interpret a cron expression, and convert it to its internal timing format:

Screen Shot 2022-05-13 at 10 02 08 AM

But the problem is, 7 doesn't divide evenly into 12, so what you end up with is this:

Screen Shot 2022-05-13 at 10 02 22 AM

In January and August, on the 1st, at 12:00am

So it picks up the first 7 month gap, but then it runs into the end of the year, so it would just repeat in January again, meaning the 2nd gap would be only 5 months.

This is unfortunately the best Cronicle v0 can do given the format of its internal timing object, which is just arrays of months, days, hours, minutes, etc. Example:

{ "minutes":[0], "hours":[0], "days":[1], "months":[1,8] }

I will say this, however. Cronicle v2.0 (a.k.a Orchestra, due for release this year, in 2022) has a new feature where you can specify a series of exact future dates/times for an event to run. Using this, you could populate the event timing for many years in the future (your case is easy because it's only ~2 events per year).

jhuckaby avatar May 13 '22 17:05 jhuckaby

I believe in actual cron */7 also means "every January and August", not "every 7 months". Cron is stateless (doesn't keep initial start time), so it can't really handle uneven intervals.
There is kind of workaround in cronicle though - you can update event schedule upon completion by emitting "update_event" object: https://github.com/jhuckaby/Cronicle#updating-the-event

here is a sample shell script for shellplug, don't forget to check "Interpret JSON":

#!/usr/bin/env bash

NEXT_MONTH=$(date -d "$(date +%Y-%m-1) +7 month" +%-m)
echo 'if you see json string below you forgot to check "interpret JSON" box'
echo "{ \"update_event\": { \"timing\": { \"minutes\": [0], \"hours\": [0], \"days\": [1], \"months\": [ $NEXT_MONTH]}  } }"

If you using python or node script you can calculate next month as (current_month + 7) % 12 The gotcha here is if you run event manually in between it will skew your desired schedule. You can control it via JOB_SOURCE variable. If you run it manually it will have some value.

In general should be doable to add state to schedule in cronicle, to use arbitrary intervals, especially assuming that @jhuckaby mentioned there will be start/end dates for events on the next cronicle version.

mikeTWC1984 avatar May 14 '22 02:05 mikeTWC1984