OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Cannot fetch Camunda job variables in pyzeebe worker

  • Thread starter Thread starter okaeiz
  • Start date Start date
O

okaeiz

Guest
I have written a Python pyzeebe worker that is supposed to interact with my database using the values that the variables of the previous user task in the Camunda BPMN hold. I have defined a user task with a form. I have also created a service task and defined the taskDefinition.

It seems like the worker can indeed communicate with my zeebe but it is unable to fetch the variables of the form.

Code:
from pyzeebe import ZeebeWorker, Job, create_insecure_channel
import asyncio
import psycopg2
import logging
async def handle_database_transaction(job: Job) -> dict:
    variables = job.variables

    # Log the received variables at INFO level
    logging.info(f"Received variables: {variables}")

    selected_date = variables.get('selected_date')
    selected_project_id = int(variables.get('selected_project_id')) if variables.get('selected_project_id') else None

    # Log the extracted field values
    logging.info(f"Selected date: {selected_date}, Project ID: {selected_project_id}")

    # if selected_date and selected_project_id is not None, I perform the insert query with my database.

    return {}

And here is the MappingIO in my BPMN:

Code:
<zeebe:ioMapping>
   <zeebe:output source="=select_0swn49" target="output_project" />
   <zeebe:output source="=datetime_gporzh" target="output_date" />
</zeebe:ioMapping>
<zeebe:ioMapping>
   <zeebe:input source="=output_project" target="selected_project_id" />
   <zeebe:input source="=output_date" target="selected_date" />
</zeebe:ioMapping>

What part of the procedure am I doing wrong?
<p>I have written a Python <code>pyzeebe</code> worker that is supposed to interact with my database using the values that the variables of the previous user task in the <code>Camunda BPMN</code> hold. I have defined a user task with a form. I have also created a service task and defined the <code>taskDefinition</code>.</p>
<p>It seems like the worker can indeed communicate with my <code>zeebe</code> but it is unable to fetch the variables of the form.</p>
<pre class="lang-py prettyprint-override"><code>from pyzeebe import ZeebeWorker, Job, create_insecure_channel
import asyncio
import psycopg2
import logging
async def handle_database_transaction(job: Job) -> dict:
variables = job.variables

# Log the received variables at INFO level
logging.info(f"Received variables: {variables}")

selected_date = variables.get('selected_date')
selected_project_id = int(variables.get('selected_project_id')) if variables.get('selected_project_id') else None

# Log the extracted field values
logging.info(f"Selected date: {selected_date}, Project ID: {selected_project_id}")

# if selected_date and selected_project_id is not None, I perform the insert query with my database.

return {}
</code></pre>
<p>And here is the MappingIO in my BPMN:</p>
<pre class="lang-xml prettyprint-override"><code><zeebe:ioMapping>
<zeebe:output source="=select_0swn49" target="output_project" />
<zeebe:output source="=datetime_gporzh" target="output_date" />
</zeebe:ioMapping>
<zeebe:ioMapping>
<zeebe:input source="=output_project" target="selected_project_id" />
<zeebe:input source="=output_date" target="selected_date" />
</zeebe:ioMapping>
</code></pre>
<p>What part of the procedure am I doing wrong?</p>
 
Top