Socket
Socket
Sign inDemoInstall

cron

Package Overview
Dependencies
2
Maintainers
2
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.1 to 1.6.0

examples/in_the_past.js

40

lib/cron.js

@@ -146,2 +146,7 @@ (function(root, factory) {

if (this.realDate) {
const diff = moment().diff(date);
if (diff > 0) {
throw new Error('WARNING: Date in past. Will never be fired.');
}
return date;

@@ -217,21 +222,11 @@ }

if (this.realDate && start < new Date()) {
throw new Error('WARNING: Date in past. Will never be fired.');
}
if (this.realDate) {
return date;
}
/*
max itterations shouldn't be more than
11 months + 30 days + 23 hours + 59 minutes + 59 seconds
anything more than that value should be considered a bug.
note: *2 is added incase we missed something.
*/
var MAX_ITERATIONS = (11 + 30 + 23 + 59 + 59) * 2;
var i = 0;
// it shouldn't take more than 5 seconds to find the next execution time
// being very generous with this. Throw error if it takes too long to find the next time to protect from
// infinite loop.
var finding = true;
var findingTimeout = setTimeout(function() {
finding = false;
}, 5000);
// determine next date
while (true) {
i++;
var diff = date - start;

@@ -244,7 +239,9 @@ var prevMonth = date.month();

if (i > MAX_ITERATIONS) {
if (!finding) {
throw new Error(
`Something went wrong. cron reached maximum iterations.
Please open an issue (https://github.com/kelektiv/node-cron/issues/new) and provide the following string
Time Zone: ${zone || '""'} - Cron String: ${this} - UTC offset: ${date.format('Z')} - current Date: ${moment().toString()}`
`Something went wrong. cron reached maximum iterations.
Please open an issue (https://github.com/kelektiv/node-cron/issues/new) and provide the following string
Time Zone: ${zone || '""'} - Cron String: ${this} - UTC offset: ${date.format(
'Z'
)} - current Date: ${moment().toString()}`
);

@@ -353,2 +350,3 @@ }

clearTimeout(findingTimeout);
return date;

@@ -355,0 +353,0 @@ },

{
"name": "cron",
"description": "Cron jobs for your node",
"version": "1.5.1",
"version": "1.6.0",
"author": "Nick Campbell <nicholas.j.campbell@gmail.com> (http://github.com/ncb000gt)",

@@ -6,0 +6,0 @@ "bugs": {

@@ -93,2 +93,22 @@ node-cron

Gotchas
==
* Millisecond level granularity in JS or moment date objects.
Because computers take time to do things, there may be some delay in execution.
This should be on the order of milliseconds. This module doesn't allow MS level
granularity for the regular cron syntax, but _does_ allow you to specify a real
date of execution in either a javascript date object or a moment object.
When this happens you may find that you aren't able to execute a job that
_should_ run in the future like with `new Date().setMilliseconds(new
Date().getMilliseconds() + 1)`. This is due to those cycles of execution
above. This wont be the same for everyone because of compute speed. When I
tried it locally I saw that somewhere around the 4-5 ms mark was where I got
consistent ticks using real dates, but anything less than that would result
in an exception. This could be really confusing. We could restrict the
granularity for all dates to seconds, but felt that it wasn't a huge problem
so long as you were made aware. If this becomes more of an issue, We can
revisit it.
API

@@ -95,0 +115,0 @@ ==

@@ -6,2 +6,4 @@ var chai = require('chai');

/* eslint-disable no-new */
describe('cron', function() {

@@ -548,3 +550,3 @@ it('should run every second (* * * * * *)', function() {

expect(function() {
new cron.CronJob({ // ignore eslint error here
new cron.CronJob({
cronTime: '* * * * * *',

@@ -551,0 +553,0 @@ onTick: function() {},

@@ -7,3 +7,3 @@ var chai = require('chai');

// most eslint errors here are due to side effects. i don't care much about them right now
/* eslint-disable no-new */

@@ -174,3 +174,4 @@ describe('crontime', function() {

it('should test next real date', function() {
var ct = new cron.CronTime(new Date());
var initialDate = new Date()
var ct = new cron.CronTime(initialDate);

@@ -180,4 +181,8 @@ var nextDate = new Date();

expect(nextDate).to.be.gt(ct.source._d);
var nextdt = ct._getNextDateFrom(nextDate);
expect(nextdt.isSame(nextDate)).to.be.true;
var nextdt = ct.sendAt(0);
// there shouldn't be a "next date" when using a real date.
// execution happens once
// so the return should be the date passed in unless explicitly reset
expect(nextdt.isBefore(nextDate)).to.be.true;
expect(nextdt.isSame(initialDate)).to.be.true;
});

@@ -184,0 +189,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc