Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function mapCronToHourFormat(cronExpression) {
try {
cronstrue.toString(cronExpression);
} catch (_) {
return null;
}
const cronParts = cronExpression.split(' ');
if (cronParts.length === 6) {
// disregard seconds component
cronParts.shift();
}
const [cronMinute, cronHour, cronDayOfMonth, cronMonth, cronDaysOfWeek] = cronParts;
const time = {};
time.minute = cronMinute.includes('*') ? 0 : Number(cronMinute);
time.date = cronDayOfMonth.includes('*') ? 1 : Number(cronDayOfMonth);
time.month = cronMonth.includes('*') ? 1 : Number(cronMonth);
time.days = cronDaysOfWeek.includes('*') ? ['MON'] : cronDaysOfWeek.split(',');
getData: ({status, spec, metadata }) => {
return [
['Created:', `${metadata.creationTimestamp} ( ${toHumanizedAge(metadata.creationTimestamp)} ago )`],
['Schedule:', `${spec.schedule} ( ${cronstrue.toString(spec.schedule)} )`],
['Concurrency Policy:', spec.concurrencyPolicy],
['Suspend', spec.suspend],
// ['Starting Deadline Seconds:', spec.startingDeadlineSeconds || ''],
['Selector:', (spec.selector && spec.selector.matchLabels) || ''],
['Parallelism:', spec.parallelism || ''],
['Last Schedule Time:', status.lastScheduleTime],
//Completions: // => need to get details of owned Jobs for this...
]
},
},
export function validateRollupCron(rollupCron) {
if (!rollupCron || !rollupCron.trim()) {
return [
,
];
}
try {
cronstrue.toString(rollupCron);
} catch (error) {
const prefix = 'Error: ';
const prefixIndex = error.indexOf(prefix);
// Note: cronstrue ships with a localizable version. Refer to the docs for more
// info on how we can display a localized error value.
return error.substring(prefixIndex + prefix.length);
}
return undefined;
}
preview: function() {
return this.manual ? 'Imports will run manually' : cronstrue.toString(this.expression)
}
},
export function getReadableCronDescriptor(expression) {
return cronstrue.toString(expression);
}
export const getTimeFromCronExpr = (cronValue) => {
let result;
try {
result = cronstrue.toString(cronValue)
} catch (err) {
}
return result || ''
};
const getNaturalLanguageCronString = (cronSchedule: string) => {
try {
return cronstrue.toString(cronSchedule);
} catch {
return "Invalid cron string";
}
};
Object.entries(requirements[`procs-${name}`]).forEach(([proc, ext]) => {
if (ext.type === 'cron') {
res.push([name, proc, `taskcluster.${name}`, ext.deadline, cronstrue.toString(ext.schedule)]);
}
if (ext.type === 'background' && ext.subType === 'iterate') {
res.push([name, proc, `taskcluster.${name}`, 'continuous', 'continuous']);
}
});
function cronValidator (value, allState) {
if (isRequired(value) && !allState.run_immediately) {
return 'Required if run immediately is unchecked'
}
if(value){
try {
cronstrue.toString(value)
} catch (err) {
return 'illegal cron input'
}
}
}
function emailsValidator () {
export function getReadableCronDescriptor(expression) {
if (expression == "@hourly") {
expression = "0 * * * *"
} else if (expression == "@daily") {
expression = "0 0 * * *"
} else if (expression == "@weekly") {
expression = "0 0 * * 0"
}
return cronstrue.toString(expression);
}