Giter Club home page Giter Club logo

moleculer-cron's People

Contributors

ccfiel avatar davidroman0o avatar dependabot[bot] avatar icebob avatar krifamed avatar wradgio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

moleculer-cron's Issues

Update required

Does not support latest moleculer version, request you to update to support latest moleculer, node and npm versions.

request to publish to npm

Would it be possible to have all the newer goodness in this repository published to the NPM registry?

How can I call methods?

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?

setTime() doesn't restart job

@davidroman0O,

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.

New version

Hi David,
could you release a new version to NPM? Because README updated, but the last release is 0.0.1 on npm.

License?

Hey @davidroman0O, would you mind adding a license to this repo? We would love to use it but can't without a license.

thanks

[Question] Concurrency

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?

Job is not running on runOnInit and onTick is ticked once

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();
	},

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.