Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use local system time #9

Merged
merged 1 commit into from
Apr 24, 2019
Merged

Use local system time #9

merged 1 commit into from
Apr 24, 2019

Conversation

chdanielmueller
Copy link
Contributor

@chdanielmueller chdanielmueller commented Apr 12, 2019

Allow via option boolean useLocalTime to use the local system time instead of UTC for intervals.
Maybe does not solve the timezone/summertime issue for everyone but for me this should do it.
closes #8

To test you can use the following example and check the sleepUntil timestamp in the MongoDB. (Unless you are in a UTC timezone)

import { MongoClient } from 'mongodb';
import { MongoCron } from '../src';
import { promise as sleep } from 'es6-sleep';
import * as moment from 'moment';

(async function() {
  const mongo = await MongoClient.connect('mongodb://localhost:27017', { useNewUrlParser: true });
  const db = mongo.db('test');
  const collection = db.collection('jobs');

  const cron = new MongoCron({
    collection,
    onDocument: (doc) => console.log('onDocument', doc),
    onError: (err) => console.log(err),
    onStart: () => console.log('started ...'),
    onStop: () => console.log('stopped'),
    nextDelay: 1000,
    reprocessDelay: 1000,
    idleDelay: 10000,
    lockDuration: 600000,
    useLocalTime: true // New option
  });

  await collection.insertMany([
    { name: 'Job interval',
      sleepUntil: moment().toDate(),
      interval: '* * 20 * * *'
    }
  ]);

  cron.start();
  await sleep(30000);
  cron.stop();

})().catch(console.error);

@xpepermint
Copy link
Owner

Looks good ... let me do some more tests on this ...

@xpepermint
Copy link
Owner

@chdanielmueller can you please add tests for this new feature? I can merge then ...

@chdanielmueller
Copy link
Contributor Author

@xpepermint what kind of tests would you like?
Do you want to duplicate the existing test suite and run them with the new setting?

@xpepermint
Copy link
Owner

We have to cover this feature with tests here https://github.com/xpepermint/mongodb-cron/blob/master/src/tests/cron.test.ts.

@chdanielmueller
Copy link
Contributor Author

@xpepermint I'm a bit clueless at the moment how to write such a test.
What should the test do step by step?

@xpepermint
Copy link
Owner

Hum ... then I'll have to do it ;). Give me a few days. Use your branch until then.

@xpepermint
Copy link
Owner

OK, some more context ... when bunkat/later#95 is resolved, we will further upgrade this feature. For now, what you did is valid (exactly as stated in Later's docs).

@xpepermint xpepermint merged commit 4dfa2bb into xpepermint:master Apr 24, 2019
@xpepermint
Copy link
Owner

Adding tests in another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timezone / Summer time support
2 participants