Installations
npm install moleculer-cron
Releases
Unable to fetch releases
Developer
davidroman0O
Developer Guide
Module System
CommonJS
Min. Node Version
>= 6.x.x
Typescript Support
Yes
Node Version
22.4.1
NPM Version
10.8.1
Statistics
38 Stars
53 Commits
25 Forks
2 Watching
6 Branches
6 Contributors
Updated on 19 Jul 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
326,246
Last day
32.4%
282
Compared to previous day
Last week
0.4%
1,428
Compared to previous week
Last month
17.1%
6,030
Compared to previous month
Last year
-0.4%
69,772
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
moleculer-cron
Cron mixin for Moleculer using cron.
Description
Easy to use cron with Moleculer!
Install
1$ npm install moleculer-cron --save
Usage
Create cron service
Specify all of your cron tasks inside the settings.cronJobs
array of the service.
1const CronMixin = require("moleculer-cron"); 2 3broker.createService({ 4 name: "cron-job", 5 6 mixins: [CronMixin], 7 8 settings: { 9 cronJobs: [ 10 { 11 name: "jobHelloWorld", 12 cronTime: '*/5 * * * * *', // Run every 5 seconds 13 manualStart: true, // This job needs to be started manually 14 onTick: async function() { 15 this.logger.info('JobHelloWorld ticked'); 16 try { 17 const data = await this.broker.call("cron-job.say"); 18 this.logger.info("Oh!", data); 19 20 // Stop this job and start the other one 21 this.stopJob("jobHelloWorld"); 22 this.startJob("jobToggle"); 23 this.logger.info("Stopped JobHelloWorld and started JobToggle"); 24 } catch (e) { 25 this.logger.info("error ", e); 26 } 27 }, 28 onInitialize: function() { 29 this.logger.info("JobHelloWorld is init"); 30 // This job is manual start, so it won't start automatically 31 }, 32 onComplete: function() { 33 this.logger.info("JobHelloWorld is stopped"); 34 } 35 }, 36 { 37 name: "jobToggle", 38 cronTime: '*/5 * * * * *', // Run every 5 seconds 39 onTick: function() { 40 this.logger.info('JobToggle ticked'); 41 42 // Stop this job and start the other one 43 this.stopJob("jobToggle"); 44 this.startJob("jobHelloWorld"); 45 this.logger.info("Stopped JobToggle and started JobHelloWorld"); 46 }, 47 onInitialize: function() { 48 this.logger.info("JobToggle is init"); 49 // This job will start automatically 50 }, 51 onComplete: function() { 52 this.logger.info("JobToggle is stopped"); 53 } 54 } 55 ] 56 }, 57 58 actions: { 59 say: { 60 handler() { 61 return "HelloWorld!"; 62 } 63 }, 64 } 65});
Available Cron patterns:
- Asterisk. E.g. *
- Ranges. E.g. 1-3,5
- Steps. E.g. */2
Read up on cron patterns here. Note that this library uses six fields, with 1 second as the finest granularity.
Cron Ranges
- Seconds: 0-59
- Minutes: 0-59
- Hours: 0-23
- Day of Month: 1-31
- Months: 0-11 (Jan-Dec)
- Day of Week: 0-6 (Sun-Sat)
API
Job Configuration
name
- [REQUIRED] - Set a name for the job.cronTime
- [REQUIRED] - The time to fire off your job. This can be in the form of cron syntax or a JS Date object.manualStart
- [OPTIONAL] - Specifies whether to start the job just before exiting the constructor. Default is false.timeZone
- [OPTIONAL] - Specify the timezone for the execution. Check all timezones available at Moment Timezone Website.onInitialize
- [OPTIONAL] - Executed before the cron job is created.onStart
- [OPTIONAL] - When the cron is starting.onStop
- [OPTIONAL] - When the cron is stopping.onComplete
- [OPTIONAL] - A function that will fire when the job is stopped.onTick
- [REQUIRED] - The function to fire at the specified time.
Mixin Methods
startJob(jobName)
- Starts the specified job.stopJob(jobName)
- Stops the specified job.getJob(jobName)
- Returns the job object for the specified job name.
Job Object Methods
startJob()
- Starts the job.stopJob()
- Stops the job.lastDate()
- Returns the last execution date of the job.running()
- Returns whether the job is currently running.setTime(time)
- Changes the time for the job.time
can be a cron string or a Date object.nextDates(count)
- Returns an array of the nextcount
dates that the job will run.addCallback(callback)
- Adds an additional callback function to be executed when the job ticks.
Utility Methods
getCronTime(time)
- Returns a CronTime instance for the given time.
Notes
For any issues or feature requests, please create an issue on the GitHub repository. Make sure to search existing issues before creating a new one.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 2/10 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 25 are checked with a SAST tool
Reason
33 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-c6rq-rjc2-86v2
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-xf5p-87ch-gxw2
- Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj
- Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-hxm2-r34f-qmc5
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-mxhp-79qh-mcx6
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-cf4h-3jhx-xvhq
Score
2
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More