Worker

class mcai_worker_sdk.Worker

Worker base class to extend to define your own worker.

This class defines several abstract methods that may be re-implemented. However, most of them will be directly called and you won’t need to call them explicitly.

Parameters:

Warning

The constructor may not be re-implemented. Use the setup() method instead.

setup()

Method called once to set up the worker. This method should not be called explicitly but will be called automatically after worker initialization.

This method may be used to load specific resources, perform checks, etc. before processing jobs.

Note

This method is optional but must be used instead of re-defining the constructor.

process(channel, parameters, job_id)

Method called for processing the job. This is were the major logic of your worker should reside.

Parameters:
  • channel (McaiChannel) – Channel to send progression and status to MCAI backend.

  • parameters (WorkerParameters) – Class definition of the worker’s parameters.

  • job_id (int) – ID of the current job.

Returns:

A dictionnary of key, values that will be sent back to MCAI backend.

Return type:

dict

Raises:

NotImplementedError

Note

You do not have to call this method explicitly, but you must define it. It will be called everytime a job needs to be processed (i.e everytime a message arrives).

start()

Method called for starting the worker. Once called, the worker will automatically start listening to new orders to process.

This is the only method you will have to call explicitly, other methods will be called directly by the SDK.

Warning

This method must not be re-implemented.