Cluster lib isMaster


#1

Enonic version: 7.0.2
OS: Linux Mint 19.2

I’m trying use the cluster lib, because my task is started more than 1 time in cluster when I not used the lib.
But when I executed the code in cluster, the task is not started.
The code of job (job-callTask) is this:

exports.run = function () {
  if (clusterLib.isMaster()) {
    log.info('Executing task.....')
    taskLib.submitNamed({
      name: 'callTask'
    })
  }
}

This is the logs in the server:

17:04:59.999 INFO  c.e.app.cronjob.runner.JobRunnerImpl - Executing job [myapp:job-callTask]
17:05:00.014 INFO  c.e.app.cronjob.runner.JobRunnerImpl - Executed job [myapp:job-callTask] in 13 ms

And the log that I put in the conditional block is not printed. The task is not started too.
Do you have any idea what I making wrong?

PS.: I used the “Cronjob App” to call the task.
PS.: I tried insert the conditional of isMaster() in the task, but not works too.


#2

If the Cronjob App has the same problem as your code, then the problem likely isn’t in your code, but has something to do with the cluster setup.

Have you taken a look at the statistics endpoint for each of your sever nodes?
https://developer.enonic.com/docs/xp/stable/runtime/statistics

If you examine the cluster statistics underneath http://<hostname>:2609/cluster, then that should tell you the isMaster value for that node.

Example result:
{“name”:“mycluster”,“localNode”:{“isMaster”:true,“id”:“dTpoWtWoTlaf3_1h64mb6Q”,“hostName”:“local”,“version”:“2.4.6”,“numberOfNodesSeen”:1},“members”:[{“isMaster”:true,“id”:“dTpoWtWoTlaf3_1h64mb6Q”,“hostName”:“local”,“version”:“2.4.6”,“address”:“local[1]”,“name”:“37f9ec49-a801-48ce-b22b-b77d16ffc49c”,“isDataNode”:true,“isClientNode”:false}],“state”:“GREEN”}