Last updated January 1, 2021
Learn how to add cpacity blocks to the schedule
Capacity blocks are the main building blocks for scheduling time for the organization.
Capacity blocks use a modified cron syntax to store recurring blocks. Capacity blocks within resource management can be configured manually or through cron expressions. For advanced logic not achievable with the user interface, you can manually enter a cron expression.
By default, cron syntax is 5 or 6 fields separated by spaces. The fields are as follows:
# ┌───────────── second (0 - 59) (optional, missing for 5 fields)
# │ ┌───────────── minute (0 - 59)
# │ │ ┌───────────── hour (0 - 23)
# │ │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)
# │ │ │ │ │ │
# │ │ │ │ │ │
# * * * * * *
Any 5 or 6 field expressions will be resolved with this logic. We have extended this syntax to include three more fields, any expression in excess of 6 fields:
# ┌───────────── year (1 - infinity)
# │ ┌───────────── days since epoch (0 - infinity) (0 = 1-Jan-1970)
# │ │ ┌───────────── months since epoch (1 - infinity) (1 = Jan 1970)
# │ │ │
# │ │ │
# * * *
The “year” field allows us to specify one-off events in cron, and every X years events. The “days/months since epoch” field allow us to specify every X days. Using some operations, we can make weeks since epoch, using grouping in cron.
The millisecond timestamp for the start of 1.1.1970 in the local timezone will be marked as localEpoch. This is not necessarily 0 in the unix epoch, due to timezones. For the moment of time we’re observing, labeled target, let us keep the date part, and replace the time part with noon. This way we have some leeway when calculating the timestamp delta, as DST switches can mess with exact alignment.
Logic:
const MILLIS_IN_DAY = 24 * 3600 * 1000;
const targetTimestamp = target.set({ hour:12, minute:0, second: 0, millisecond: 0}).toMillis();
const daysPassed = Math.floor((targetTimestamp - localEpoch) / MILLIS_IN_DAY);
Assuming we mark literal values with V1 and V2, and step with S, the following are valid cron values:
V1 - that literal value
V1-V2 - all literal values in the given range, inclusively
V1-V2/S - similar to above, but we move with a step of S; So 2-9/3 would cover 2,5,8
The values can be comma separated, representing a union between the queries.
A new shape we are adding is V1/S, where we start V1 and iterate with a step through all legal values.
It is equivalent to V1-maxValue/S.
This allows for expressing a starting point for infinite ranges, like years or days and months since epoch, while still working correctly for other fields too.
We have additionally added negative numbers, allowing you to specify things starting from the highest legal value.
This is most relevant for end of the month behavior, but can be a convenient syntax for situations as well.
For example, a cron of 0 0 12 -2 * *
will trigger at noon of the second last day of the month - Jan 30th, Feb 27th (for non-leap years, 28th on leap years), Mar 30th, Apr 29th, etc.
Reference: example default cron expressions.