Workload Scheduler for Node.js script - is it equivalent to cron jobs in Bluemix?

不想你离开。 提交于 2019-12-22 05:41:05

问题


I'm trying to call node file.js with Bluemix Workload Scheduler every morning; file.js is in the root of my node.js project; file.js is not my server file. I used to use cron but it seems like "BlueMix doesn't have a concept of cron jobs."

As result for the (only) step of my process, I got "node : command not found"

I think I missed something. Is it even possible to do this with Workload Scheduler or should I find alternative options?

MORE INFORMATION

I'm trying to do :

var wls = new WorkloadService(credentials);

var wp = new WAProcess("MyProcessName", "DescriptionProcess");
wp.addStep(new CommandStep("node file.js", myAgentName));
wp.addTrigger( TriggerFactory.repeatDaily(1) );

wls.createAndEnableTask(wp, function(res){
    wls.runTask(res.id, function(){console.log("Process is created and started.")});
});

I can see in "IBM Workload Automation on Cloud - Application Lab" that the process is created and started. A few later, process has failed saying "node command not found"

I think i read in the documentation that the agent can only call local system commands (such as cat, pwd ... ) or commands that interact with outside (for REST services call). So there's no way it can find node command or file.js.

Unless I install everything on the agent ? Documentation says we can install programs in /home/wauser/workspace directory by using curl command. Is that how I should proceed ?


回答1:


You should modify your NodeJS application to let it expose a method that can be run using the curl command and provides the proper output and logging. The curl calling the method will then be run in the Workload Scheduler job. Workload Scheduler service is not part of the node runtime.




回答2:


I suppose your application is using the built-in node.js buildpack in Bluemix. If that's true then node should be in the path. But it's not clear to me this scheduler service can parse the command "node file.js" correctly. Maybe it is expecting only one command without parameters? Could you try to put a script file that executes "node file.js", say run.sh, and then let the CommandStep invoke this script?




回答3:


As said by lmosca in her answer, Workload Scheduler service is running outside Node.js, but you can use it to trigger you code running on Node.js and exposed as REST.

In addition to using curl, you can define a REST step in your process in Workload Scheduler, to call your REST API without using curl.



来源:https://stackoverflow.com/questions/30188580/workload-scheduler-for-node-js-script-is-it-equivalent-to-cron-jobs-in-bluemix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!