1

I want to run a task every 5 minutes using actionhero task in node.js, the task that I defined in task folder is as below:

'use strict';
exports.task = {
    name: 'scheduleTask',
    description: 'Convert Temp Data Into Portal',
    frequency: 300000,
    queue: 'syncPortal',

    run: function (api, params, next) {
        api.services.ErpToPortal
        .syncInitializeFunctions({})
        .then(() => {
            return api.services.ErpToPortal
            .syncPerson({})
        })
        .then(() => {
            return api.services.ErpToPortal
                .syncContractors({})
        })
        .then((res) => {
            next(null, res);
        })
        .catch(function (err) {
            api.log(err, 'error', err);
            next(err);
        });
    }
};

My Problem here is that the task does not start automatically while starting actionhero api server, am I missing anything here ? as I understood from actionherojs documenation, after defining frequency for a task, by starting actionhero api server, the task should be started automatically.

A.A Noman
  • 5,244
  • 9
  • 24
  • 46
Moya
  • 21
  • 2

2 Answers2

0

You will need to make sure that the config in config/tasks.js has an amount of running workers that is greater to 1 and that the scheduler is set to enabled: true. By default this is not the case and the queue isn't available out-of-the-box.

nembleton
  • 2,392
  • 1
  • 18
  • 20
  • thank's a lot for your answer , in task.js,the parameter are set like this: scheduler: true,queues: ['*'], and i should say that i have wrote another task's for sending emails and another task for cleaning some temporary files and inside an action using api.tasks.enqueue() i'm scheduling some work inside their queue and those tasks are working properly, but the final task for doing a repetitive task with frequency > 0 is not working automatically. – Moya Dec 11 '17 at 05:44
  • Hmm. How many workers min / max have you set? Is it higher to 0? – nembleton Dec 11 '17 at 07:07
  • The other thing that has happened to me sometimes is that I had crashes during the queue processing and never called "next()" and it effectively locked the task queue. The way I fix this on my development machine is to login to Redis using Fastoredis and clearing whatever is in the database to effectively reset the queue. – nembleton Dec 11 '17 at 07:08
  • minTaskProcessors: 2,maxTaskProcessors: 20, these are other paramters in my config. – Moya Dec 11 '17 at 09:50
0

At actionhero you have to enqueue task to run first time.

api.tasks.enqueue("taskname",params,'queue')

After this if you want to repeat task use frequency definition at task

Hasan Veli Soyalan
  • 2,428
  • 20
  • 24