Skip to content

Worker Base

The WorkerBase class inherits from Everysk's BaseDict class and it is used widely in the creation of workers.

from everysk.sdk.worker_base import WorkerBase

The WorkerBase class has three main methods that should be overridden by the worker's subclass since they raise implementation errors.


Handle Inputs

The handle_inputs() method is called by the worker's run() method. It is used to set all the input data that the worker needs in order to function.

For instance, if we have a field in the interface that is used to set the worker's name, we would set it in the handle_inputs() method as follows:

class MyWorker(WorkerBase):
    name = None

    def handle_inputs(self):
        self.name = self.script_inputs.name


Handle Tasks

The handle_tasks() method is called by the worker's run() method. It is used to process the tasks that the worker needs to perform.

For instance, if we wish that the worker's name is standardized to lowercase, we would do it in the handle_tasks() method as follows:

def handle_tasks(self):
    self.name = self.name.lower()


Handle Outputs

After we have all the inputs and tasks processed by the worker, we need to set the outputs that will be sent back to the interface. This is done in the handle_outputs() method.

In the following example, after setting the workers name, we may wish to return a message to the user letting them know that the worker's name was successfully set:

def handle_outputs(self):
    self.output = f"Worker's name set to {self.name}"
    out = BaseDict(data=self.output)
    return out


More Information

For more information on how to create a worker, please refer to the Worker Creation documentation.