davidroman0o / moleculer-cron Goto Github PK
View Code? Open in Web Editor NEWMoleculer Addons - Cron tasks
License: MIT License
Moleculer Addons - Cron tasks
License: MIT License
Does not support latest moleculer version, request you to update to support latest moleculer, node and npm versions.
Please add an index.d.ts so that this will work properly with typescript.
Would it be possible to have all the newer goodness in this repository published to the NPM registry?
I created methods but when I call inside action I receive an error:
TypeError: this.myMethod is not a function
code:
crons: [
{
name: "Cron-Job",
cronTime: process.env.CRON_TIMER,
onTick: function() {
this.getLocalService("RefreshToken").actions.mainAction();
},
manualStart: false
},
],
actions: {
mainAction: {
async handler() {
const result = this.myMethod();
// do something with result;
},
},
},
methods: {
myMethod() {
return "something";
}
}
What is missing?
In the old version of cron setTime() doesn't restart job:
CronJob.prototype.setTime = function(time) {
if (!(time instanceof CronTime)) throw new Error('time must be an instance of CronTime.');
this.stop();
this.cronTime = time;
};
Please write about it in the documentation or you can update cron.
Hi David,
could you release a new version to NPM? Because README updated, but the last release is 0.0.1 on npm.
Need an update on Moleculer peer dependency from 0.11 to 0.14.x. Can this be done?
Hey @davidroman0O, would you mind adding a license to this repo? We would love to use it but can't without a license.
thanks
How does this service work with regard concurrency control? If you have multiple instances of the cron service on a single node, or instances of the cron service running on multiple nodes, won't this duplicate running the job on every instance?
Like, 31 Aug 2022 and next 30 Sep 2022 and next 31 Oct 2022
I have updated node 14 to node 20, so I updated moleculer-cron:0.0.2 to .0.04, but the same is not working in 0.0.4. I have pasted the snippets for further analysis.
node -v
20.11.1
"moleculer": "0.14.32",
"moleculer-cron": "0.0.4",
dep - "cron":"1.8,2"
"moleculer-web": "0.10.7",
import { Service, ServiceBroker, ServiceSchema } from 'moleculer'; --
import Cron from 'moleculer-cron';
export default class SchedulerService extends Service
{
public constructor(public broker: ServiceBroker, schema: ServiceSchema<{}> = {})
{
super(broker);
this.parseServiceSchema({
name: 'scheduler',
version: 1,
mixins: [Cron],
settings: {
rest: '/',
$noServiceNamePrefix: false,
$noVersionPrefix: true,
},
hooks: {
before: {
},
},
actions: {
// actions
},
methods: {
// nothing
},
dependencies: [
'config',
],
started: async () =>
{
},
crons: [
{
name: 'AdapterConfigScheduler',
cronTime: '*/10 * * * *',
onTick: async () =>
{
console.log('ticked.............'); // PRINTING ONCE
await broker.call('config.networkAdapterConfig', {}, { parentCtx: null });
},
runOnInit: async () =>
{
console.log('runOnInit.............'); // NOT PRINTING
await broker.call('config.networkAdapterConfig', {}, { parentCtx: null });
},
timeZone: 'America/Los_Angeles',
},
],
});
}
}
moleculer-cron\src\index.js
created() {
this.$crons = [];
if (this.schema.crons) {
// `cron` changed their way of creating crons, so now it's a function that will proxy the instanciation
this.$crons = this.schema.crons.map((job) => {
console.log('in create.') // PRINTS
var instance_job = () => {
console.log('in create.') // NOT PRINTS, SERVER FREEZES
// cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout
var cronjob = new cron.CronJob(
job.cronTime, // cronTime
job.onTick || (_ => {}), // onTick
job.onComplete || (_ => {}), // onComplete
job.manualStart || false, // start
job.timeZone, // timeZone
Object.assign(
this.broker,
{
getJob: this.getJob,
}
), // context
job.runOnInit || (_ => {}), // runOnInit
job.utcOffset || null, // utcOffset
job.unrefTimeout || null, // unrefTimeout
)
cronjob.manualStart = job.manualStart || false
cronjob.name = job.name || this.makeid(20);
return cronjob;
};
return instance_job;
});
}
return this.Promise.resolve();
},
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.