Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async.each(crontab['jobs'], function(job,iteratorcallback) {
console.log("job is",job);
console.log("schedule is",job["schedule"]);
var options = {currentDate: d};
var interval = parser.parseExpression(job["schedule"],options);
var runtime = interval.next();
// coerce both d and runtime into a string with seconds
datestring = JSON.stringify(d);
runtimestring = JSON.stringify(runtime);
if (datestring == runtimestring) {
var lambda = new AWS.Lambda();
var params = {
FunctionName: job["function"],
InvocationType: "Event",
Payload: JSON.stringify(job["args"])
};
lambda.invoke(params, function(err,data) {
if (err) iteratorcallback(err);
else iteratorcallback(null);
});
}
if (ifModifiedSinceRawHeader) {
ifModifiedSinceHeader = new Date(ifModifiedSinceRawHeader);
}
let ifNoneMatchHeader = req.header('if-none-match');
let stats = fs.statSync(filepath);
let lastModifiedDate = new Date(util.inspect(stats.mtime));
let now = new Date();
let validUntilDate = null;
if (hasLiveData) {
// Valid until the next update + 1 second to allow intermediate caches to update
let rtUpdatePeriod = this.getCompanyDatasetConfig(company)['realTimeData']['updatePeriod'];
let nextUpdate = cronParser.parseExpression(rtUpdatePeriod).next();
validUntilDate = new Date(nextUpdate.getTime() + 1000);
} else {
if (departureTime < (now - 10800000)) {
// If departure time requested is older than 3 hours set validity for one year
validUntilDate = new Date(now.getTime() + 31536000000);
} else {
// If is not older than 3 hours it is valid for 1 day
validUntilDate = new Date(now.getTime() + (3600 * 24 * 1000))
}
}
let maxage = Math.round((validUntilDate - now) / 1000);
let etag_reference = null;
// Take into account Memento requests to define the ETag header
let timeout;
if (definition.every) {
const typeOfEvery = typeof definition.every;
if (typeOfEvery === 'string') {
// Passed a human interval:
timeout = timestring(definition.every, 'ms');
} else if (typeOfEvery === 'number') {
// Passed a ms interval:
timeout = definition.every;
} else {
throw new Error(`Unknown interval of type "${typeOfEvery}" passed to hire.`);
}
} else if (definition.cron) {
const options = { iterator: false, tz: this.tz };
const iterator = parseExpression(definition.cron, options);
const nextCronTimeout = () => iterator.next().getTime() - Date.now();
const cronTimeout = nextCronTimeout();
timeout = cronTimeout > 0 ? cronTimeout : nextCronTimeout();
}
return this.client.set(this.getJobKey(name), name, 'PX', timeout, 'NX');
}
}
async getTimeList(beginTime, endTime, datalist) {
const result = [];
const options = {
currentDate: new Date(beginTime),
endDate: new Date(endTime),
iterator: true,
};
const interval = parser.parseExpression(this.app.config.pvuvip_task_minute_time, options);
while (true) { // eslint-disable-line
try {
const obj = interval.next();
const date = new Date(obj.value.toString());
const timer = this.app.format(date, 'yyyy/MM/dd hh:mm:ss');
const items = {
time: timer,
pv: 0,
uv: 0,
ip: 0,
ajax: 0,
flow: 0,
};
datalist.forEach(item => {
if (date.getTime() === new Date(item.create_time).getTime()) {
items.pv = item.pv || 0;
async getPvUvIpList() {
const { ctx } = this;
const query = ctx.request.body;
const appId = query.appId;
// 参数校验
if (!appId) throw new Error('界面查询pvuvip:appId不能为空');
// 计算定时任务间隔
const interval = parser.parseExpression(this.app.config.pvuvip_task_minute_time);
const timer = interval.prev().toString();
const timestrat = new Date(interval.prev().toString()).getTime();
const betweenTime = Math.abs(new Date(timer).getTime() - timestrat);
const beginTime = query.beginTime || new Date(timestrat - betweenTime * 30);
const endTime = query.endTime || new Date(timestrat);
const datalist = await ctx.service.wx.pvuvip.getPvUvIpData(appId, beginTime, endTime) || [];
const result = await this.getTimeList(beginTime, endTime, datalist);
ctx.body = this.app.result({
time: betweenTime,
data: result,
});
}
// 获得单条数据
onChangeSegment(i, value) {
const invalid = this.state.invalid.slice();
const atoms = this.state.atoms.slice();
const field = CronExpression.map[i + 1]; // The .map also has seconds, skip over it
atoms[i] = value;
try {
CronExpression._parseField(
field,
value,
CronExpression.constraints[i + 1]);
} catch (e) {
invalid[i] = e.message;
return this.setState({ atoms, invalid });
}
const schedule = atoms.join(' ');
invalid[i] = false;
this.setState({ atoms, invalid, schedule }, () => {
if (this.props.onChange) this.props.onChange(this.getValue());
});
onChangeSegment(i, value) {
const invalid = this.state.invalid.slice();
const atoms = this.state.atoms.slice();
const field = CronExpression.map[i + 1]; // The .map also has seconds, skip over it
atoms[i] = value;
try {
CronExpression._parseField(
field,
value,
CronExpression.constraints[i + 1]);
} catch (e) {
invalid[i] = e.message;
return this.setState({ atoms, invalid });
}
const schedule = atoms.join(' ');
invalid[i] = false;
this.setState({ atoms, invalid, schedule }, () => {
if (this.props.onChange) this.props.onChange(this.getValue());
});
}
}
onChangeSegment(i, value) {
const invalid = this.state.invalid.slice();
const atoms = this.state.atoms.slice();
const field = CronExpression.map[i + 1]; // The .map also has seconds, skip over it
atoms[i] = value;
try {
CronExpression._parseField(
field,
value,
CronExpression.constraints[i + 1]);
} catch (e) {
invalid[i] = e.message;
return this.setState({ atoms, invalid });
}
const schedule = atoms.join(' ');
try {
let expTerms = state.cronExp.split(/\s+/)
let terms = expTerms.filter((term) => term.length !== 0)
state.cronResult = { status: -1, content: '', list: [] }
if (terms.length < 5 && !CRON_SPECIAL_TYPES.includes(state.cronExp)) {
target.classList.add('invalid')
state.cronResult = { status: -1, content: i18n.t('cronHelp.expNotComplete'), list: [] }
return false
} else {
target.classList.remove('invalid')
if (state.cronExp === '@reboot') {
state.cronResult = { status: 1, content: i18n.t('cronHelp.afterReboot'), list: [] }
return false
}
}
let interval = (state.cronExp === '@annually') ? parser.parseExpression('0 0 1 1 *', CRON_OPTIONS) : parser.parseExpression(state.cronExp, CRON_OPTIONS)
Array(parseInt(state.dateMaxCount)).fill(1).forEach((_, i) => {
state.cronResult['list'].push(interval.next()['_date'].format('YYYY-MM-DD HH:mm:ss dddd'))
})
state.cronResult['status'] = 1
if (state.cronResult['status'] >= 0) helpers.translateToLanguage(state)
} catch (err) {
console.log('Error: ' + err.message)
target.classList.add('invalid')
state.cronResult = { status: -1, content: err.message, list: [] }
return false
}
},
render() {
const schedule = this.getValue();
let nextRun;
try {
const cron = Cron.parseExpression(schedule, {
currentDate: this.state.currentDate,
});
const next = cron.next();
const startOfToday = new Date(this.state.now.valueOf());
const days = 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'.split(' ');
startOfToday.setHours(0);
startOfToday.setMinutes(0);
startOfToday.setSeconds(0);
startOfToday.setMilliseconds(0);
const deltaMinutes = (next.valueOf() - startOfToday.valueOf()) / (1000 * 60);
let day;
if (deltaMinutes < 60 * 24) {
day = 'today';