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

refactor: replace uuid with node's crypto module #394

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 0 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Expand Up @@ -28,9 +28,6 @@
"bugs": {
"url": "https://github.com/merencia/node-cron/issues"
},
"dependencies": {
"uuid": "8.3.2"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^5.7.0",
Expand Down
4 changes: 2 additions & 2 deletions src/background-scheduled-task/index.js
@@ -1,7 +1,7 @@
const EventEmitter = require('events');
const path = require('path');
const { fork } = require('child_process');
const uuid = require('uuid');
const { randomUUID } = require('crypto');

const daemonPath = `${__dirname}/daemon.js`;

Expand All @@ -17,7 +17,7 @@ class BackgroundScheduledTask extends EventEmitter {
this.cronExpression = cronExpression;
this.taskPath = taskPath;
this.options = options;
this.options.name = this.options.name || uuid.v4();
this.options.name = this.options.name || randomUUID();

if(options.scheduled){
this.start();
Expand Down
4 changes: 2 additions & 2 deletions src/scheduled-task.js
Expand Up @@ -3,7 +3,7 @@
const EventEmitter = require('events');
const Task = require('./task');
const Scheduler = require('./scheduler');
const uuid = require('uuid');
const { randomUUID } = require('crypto');

class ScheduledTask extends EventEmitter {
constructor(cronExpression, func, options) {
Expand All @@ -16,7 +16,7 @@ class ScheduledTask extends EventEmitter {
}

this.options = options;
this.options.name = this.options.name || uuid.v4();
this.options.name = this.options.name || randomUUID();

this._task = new Task(func);
this._scheduler = new Scheduler(cronExpression, options.timezone, options.recoverMissedExecutions);
Expand Down
5 changes: 3 additions & 2 deletions src/storage.js
@@ -1,3 +1,5 @@
const { randomUUID } = require('crypto');

module.exports = (() => {
if(!global.scheduledTasks){
global.scheduledTasks = new Map();
Expand All @@ -6,9 +8,8 @@ module.exports = (() => {
return {
save: (task) => {
if(!task.options){
const uuid = require('uuid');
task.options = {};
task.options.name = uuid.v4();
task.options.name = randomUUID();
}
global.scheduledTasks.set(task.options.name, task);
},
Expand Down