Job workers intermittent issue

Hi Everyone,

I have a job worker to initialize the process variable but that is not working as expected.

Sometimes worker getting invoked and sometimes not. Below are my usecase with logs.

Worker code:

    @JobWorker(type = WorkerName.LOAD_URLS, fetchAllVariables = true,name = "loadUrls")
	public Map<String, Object> connectorURLs(final JobClient jobClient, final ActivatedJob activatedJob) {
		log.info("Worker:{} has been started.", WorkerName.LOAD_URLS);

		Map<String, Object> variables = activatedJob.getVariablesAsMap();
		variables.put("test", 1234);
		
		log.info("New variables:{}", variables);
		return variables;
	}

Console log:

Now, you can the log label "New variables and Worker has not been printed in console.

Any help would be highly appreciated.

TIA.

Hi, :wave: @yadav1990 Welcome to the forum , you need to use client.newCompleteCommand(activatedJob.getKey()).variables(variables).send(); instead of return variables;

Docs: Handle variables as POJO | Camunda Platform 8 Docs

I had tried with that also but didn’t worked.And as per camunda docs autoComplete command is true by default.

Is this a different issue that your other thread?

If you set the variables with SetVariables, can you see them in Tasklist?

:no_good_man:Because the autoComplete attribute default is true, the return value will be used as process variables.

FYI: spring-zeebe/JobWorker.java at 54cbb141aedb2cd6c6db0f831857a52cbe9a0c45 · camunda-community-hub/spring-zeebe · GitHub

1 Like

@JobWorker(type = WorkerName.LOAD_URLS, fetchAllVariables = true,name = “loadUrls”)

Hi @yadav1990 . :laughing: Just a guess.

Please make sure that the WorkerName.LOAD_URLS constant value is loadUrls as you mention in process model. The name attribute of JobWorker annotation is not type.

I understand your concern and the naming conventioned already taken care.
Please have a look in below constants how I have defined. :smiley:

public static final String LOAD_URLS = "loadUrls";

@yadav1990 Please provide the code and process model you tested.

yes, this is different issue with jobWorker.And variables can be seen only if jobWorker executed successfully.

Code can’t be shared. But the usecase is to call the jobworker first to initialized some process variables and then call the connector. And the code which I have shared above is for jobWorkers.

If the job worker handler is not being invoked there are a few potential causes, including:

  1. Job worker not running
  2. Job worker not connected to broker
  3. Job worker subscribed (polling for) wrong task type

@jwulf I appreciate you on above points but not agreed completely. Please find my inline answered for above points.

  1. Job worker not running => On application startup I can see the mentioned jobWorker activated in console log and also executing intermittently.

  2. Job worker not connected to broker => If jobWorker not connected then how application is running executing other flow like connector and script task.

  3. Job worker subscribed (polling for) wrong task type => jobWorker is subscribed for serviceTask and it’s working intermittently.

Below is the code for our jobWorker

@Component
 @Slf4j
 public class VariablesInitializer {
 
     /**
      * This methods to set all the microservice urls and tokens
      * 
      * @param jobClient
      * @param activatedJob
      **/
     @JobWorker(type = WorkerName.LOAD_URLS, fetchAllVariables = true,name = "loadUrls")
     public Map<String, Object> connectorURLs(final JobClient jobClient, final ActivatedJob activatedJob) {
         log.info("Worker:{} has been started.", WorkerName.LOAD_URLS);
 
         Map<String, Object> variables = activatedJob.getVariablesAsMap();
         variables.put("test", 1234);
         log.info("New variables:{}", variables);
         return variables;
     }
}

@lzgabel . This is our code snnipet.

@Component
 @Slf4j
 public class VariablesInitializer {
 
     /**
      * This methods to set all the microservice urls and tokens
      * 
      * @param jobClient
      * @param activatedJob
      **/
     @JobWorker(type = WorkerName.LOAD_URLS, fetchAllVariables = true,name = "loadUrls")
     public Map<String, Object> connectorURLs(final JobClient jobClient, final ActivatedJob activatedJob) {
         log.info("Worker:{} has been started.", WorkerName.LOAD_URLS);
 
         Map<String, Object> variables = activatedJob.getVariablesAsMap();
         variables.put("test", 1234);
         log.info("New variables:{}", variables);
         return variables;
     }
}

@jwulf any finding on this issue?

TIA.

Can you build/share a minimal reproducible example? (eg. Worker doesn’t actually do anything, it just writes to the log and returns)
If you hard-code your type, rather than using a reference, does it work consistently there?

Asking the community (not Camunda) to try to sort this out without any way for us to try see what you’re seeing, makes it really difficult.