Netflix Conductor Workers in Python

What is Conductor

Conductor is a Microservices orchestration platform from Netflix, released under Apache 2.0 Open Source License.

Install the python client

virtualenv conductorclient
source conductorclient/bin/activate
cd ../…


This content originally appeared on DEV Community and was authored by nvn07

What is Conductor

Conductor is a Microservices orchestration platform from Netflix, released under Apache 2.0 Open Source License.

Install the python client

virtualenv conductorclient
source conductorclient/bin/activate
cd ../conductor/client/python
python setup.py install

Implement a Task Worker

ConductorWorker class is used to implement task workers.
The following script shows how to bring up two task workers named book_flight and book_car:

from __future__ import print_function
from conductor.ConductorWorker import ConductorWorker

def book_flight_task(task):
    return {'status': 'COMPLETED', 'output': {'booking_ref': 2341111, 'airline': 'delta'}, 'logs': ['trying delta', 'skipping aa']}

def book_car_task(task):
    return {'status': 'COMPLETED', 'output': {'booking_ref': "84545fdfd", 'agency': 'hertz'}, 'logs': ['trying hertz']}

def main():
    print('Starting Travel Booking workflows')
    cc = ConductorWorker('http://localhost:8080/api', 1, 0.1)
    cc.start('book_flight', book_flight_task, False)
    cc.start('book_car', book_car_task, True)

if __name__ == '__main__':
    main()

ConductorWorker parameters

server_url: str
    The url to the server hosting the conductor api.
    Ex: 'http://localhost:8080/api'

thread_count: int
    The number of threads that will be polling for and
    executing tasks in case of using the start method.

polling_interval: float
    The number of seconds that each worker thread will wait
    between polls to the conductor server.

worker_id: str, optional
    The worker_id of the worker that is going to execute the
    task. For further details, refer to the documentation
    By default, it is set to hostname of the machine

start method parameters

taskType: str
    The name of the task that the worker is looking to execute

exec_function: function
    The function that the worker will execute. The function
    must return a dict with the `status`, `output` and `logs`
    keys present. If this is not present, an Exception will be
    raised

wait: bool
    Whether the worker will block execution of further code.
    Since the workers are being run in daemon threads, when the
    program completes execution, all the threads are destroyed.
    Setting wait to True prevents the program from ending.
    If multiple workers are being called from the same program,
    all but the last start call but have wait set to False.
    The last start call must always set wait to True. If a
    single worker is being called, set wait to True.

domain: str, optional
    The domain of the task under which the worker will run. For
    further details refer to the conductor server documentation
    By default, it is set to None

See
https://github.com/Netflix/conductor/tree/main/polyglot-clients/python
for the source code and follow us on GitHub for updates.


This content originally appeared on DEV Community and was authored by nvn07


Print Share Comment Cite Upload Translate Updates
APA

nvn07 | Sciencx (2021-12-02T23:47:17+00:00) Netflix Conductor Workers in Python. Retrieved from https://www.scien.cx/2021/12/02/netflix-conductor-workers-in-python/

MLA
" » Netflix Conductor Workers in Python." nvn07 | Sciencx - Thursday December 2, 2021, https://www.scien.cx/2021/12/02/netflix-conductor-workers-in-python/
HARVARD
nvn07 | Sciencx Thursday December 2, 2021 » Netflix Conductor Workers in Python., viewed ,<https://www.scien.cx/2021/12/02/netflix-conductor-workers-in-python/>
VANCOUVER
nvn07 | Sciencx - » Netflix Conductor Workers in Python. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/02/netflix-conductor-workers-in-python/
CHICAGO
" » Netflix Conductor Workers in Python." nvn07 | Sciencx - Accessed . https://www.scien.cx/2021/12/02/netflix-conductor-workers-in-python/
IEEE
" » Netflix Conductor Workers in Python." nvn07 | Sciencx [Online]. Available: https://www.scien.cx/2021/12/02/netflix-conductor-workers-in-python/. [Accessed: ]
rf:citation
» Netflix Conductor Workers in Python | nvn07 | Sciencx | https://www.scien.cx/2021/12/02/netflix-conductor-workers-in-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.