We would like to slightly randomize the crontabs in Jenkins for
DEV@Cloud so that when people all set their jobs to run @midnight, we
don't have thousands of slaves launch. Instead we want @midnight to
mean "once a day -- most likely not midnight' and perhaps let people
use a tag in the comments of a crontab line (like #exactly) if they
really need a job to run exactly at midnight. But most people don't
need this.
Looking at how Crontabs work in Jenkins, I see that the expressions
are compiled using ANTLR into an array of Longs (and one Int) which
are used as bit arrays, with each bit specifying that a cron should be
triggered at that time for a given unit of measure. Right?
So we want to do a random circular bit shift on each unit of measure.
Something like rotateRight(bitarray,rand(UOM_MAX),UOM_MAX) so that
(say) for the hour unit of measure, we would shuffle around everyone's
0x1 @midnight bit randomly, but still preserve any intervals between
the bits (and hence the "spirit" of the cron).
What I'm coming to is that I think I need a new extension point to
make this happen. I think the ideal signature would look like this:
@Extension
public abstract class CronOverrider {
/** Called when creating the context from a form submission or in readResolve
public abstract CrontabList override (CrontabList list, Object context);
}
This (my approach) also requires an extra constructor of CronTab so
that you can create them from raw bit arrays instead of having to pass
in the expressions.
So I can work up a patch, but wanted to see if people think this is
stupid for some reason.
Ryan