简体   繁体   中英

why actionherojs Task does not start Automatically?

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM