Workload planner for Node.js script - is this equivalent to cron jobs in Bluemix?

I try to call node file.js using the Bluemix workload scheduler every morning; file.js is at the root of my node.js project; file.js is not my server file. I used to use cron, but it seems to me that "BlueMix has no idea about cron working."

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

I think I missed something. Is it possible to do this with a workload scheduler or should I find alternatives?

ADDITIONAL INFORMATION

I am 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.")}); }); 

In the "IBM Workload Automation on Cloud - Application Lab", I see that the process is created and running. A little later, the process failed, saying: "node command not found"

I think I read in the documentation that an agent can only call local system commands (e.g. cat, pwd ...) or commands that interact with an external one (to call REST services). Thus, he cannot find the command node command or file.js.

If I do not install everything on the agent? The documentation says that we can install programs in the /home/wauser/workspace directory using the curl command. So should I go on?

+6
source share
3 answers

You should modify the NodeJS application so that it can expose a method that can be started with the curl command and that provides correct output and logging. Then the curl calling the method will be run in the workload scheduler task. The workload scheduler service is not part of the node runtime.

+4
source

I suppose your application uses the built-in node.js buildpack on Bluemix. If true, then node should be on the way. But it’s not clear to me that this scheduler service can correctly parse the “node file.js” command. Maybe he expects only one command without parameters? Could you try putting a script file that executes "node file.js", say run.sh, and then let CommandStep call this script?

0
source

As lmosca said in his answer, the Workload Scheduler service works outside of Node.js, but you can use it to run code running on Node.js and displayed as REST.

In addition to using curl, you can define the REST step in your process in the workload scheduler to call your REST API without using curl.

0
source

Source: https://habr.com/ru/post/987033/


All Articles