Gathering detailed insights and metrics for @stretchshop/moleculer-cron
Gathering detailed insights and metrics for @stretchshop/moleculer-cron
Gathering detailed insights and metrics for @stretchshop/moleculer-cron
Gathering detailed insights and metrics for @stretchshop/moleculer-cron
npm install @stretchshop/moleculer-cron
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
38 Stars
53 Commits
25 Forks
2 Watching
6 Branches
6 Contributors
Updated on 19 Jul 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-72%
14
Compared to previous day
Last week
-25.8%
219
Compared to previous week
Last month
45.2%
800
Compared to previous month
Last year
420.3%
41,371
Compared to previous year
Cron mixin for Moleculer using cron.
Easy to use cron with Moleculer!
1$ npm install moleculer-cron --save
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});
Read up on cron patterns here. Note that this library uses six fields, with 1 second as the finest granularity.
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.startJob(jobName)
- Starts the specified job.stopJob(jobName)
- Stops the specified job.getJob(jobName)
- Returns the job object for the specified job name.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 next count
dates that the job will run.addCallback(callback)
- Adds an additional callback function to be executed when the job ticks.getCronTime(time)
- Returns a CronTime instance for the given time.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
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
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
33 existing vulnerabilities detected
Details
Score
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