i need to set variables to job element Instance
any way to do it in pyzeebe(python)?
Hey @CMX,
not sure if I understand you correctly - what do you mean by “job element instance”?
If you want to pass a variable from a service task back to the process instance you can so like this for instance:
@worker.task(task_type="do-something", exception_handler=on_error)
async def do_something(inputValue: str) -> dict:
return {"output": f"{inputValue} + XYZ !"}
Let me know if this was what you are looking for!
Best,
Thomas
i mean like this
from java
Command to set and/or update the variables of a given flow element (e.g. process instance, task, etc.)
zeebeClient
.newSetVariablesCommand(elementInstanceKey)
.variables(json)
.send();
Params:
elementInstanceKey – the key of the element instance to set/update the variables for
Returns:
a builder for the command
I have never seen that before besides in some older JavaDocs. Usually you would use something like this in Java:
@ZeebeWorker(type = "generate-uuid")
public void generateCertificateOfRecovery(final JobClient client, final ActivatedJob job, @ZeebeVariable String person_uuid) {
UUID _uuid = UUID.randomUUID();
client.newCompleteCommand(job.getKey())
.variables("{\"uuid\": \"" +uuid + "\"}")
.send()
.exceptionally( throwable -> { throw new RuntimeException("Could not complete job " + job, throwable); });
}
So just to recap:
You want to complete a job with a python worker and return some values to the process instance right?
i want to do something like this
add vars to the context
then throw error
then use this vars as output in boundary event
w.client.NewSetVariablesCommand().
ElementInstanceKey(job.ElementInstanceKey).
VariablesFromMap(map[string]interface{}{
consts.ErrorMessageVarName: reason,
consts.ErrorCodeVarName: errorCode,
})
w.client.NewThrowErrorCommand().
JobKey(job.Key).
ErrorCode(consts.FailScanError).
ErrorMessage(reason).
Send(ctx)
Hey @CMX - sorry for the delay!
I have been quite busy on our company’s annual retreat.
Since you want to do this in python I do recommend using the pyzeebe client. The author has some documentation up and running right here. I would suggest taking a look at it. If you use this there should be no thing as a “ElementInstanceKey”.
https://pyzeebe.readthedocs.io/en/stable/index.html
Perhaps with
https://pyzeebe.readthedocs.io/en/stable/worker_reference.html#pyzeebe.Job.set_error_status