Hi all! I'm trying to create my own custom worker ...
# ask-community
s
Hi all! I'm trying to create my own custom worker that executes on HPC via Slurm, and Ive been trying to base this off the docker worker found in https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-docker/prefect_docker/worker.py One thing that has confused me is how cancellations are handled. I'd have assumed that if a user cancels a flow run, that would make its way to the worker and the worker would terminate the container. However, I cant seem to find any code which handles cancellation of flow runs. I assume Im missing something obvious - any chance someone can point me in the right direction?
j
hey TLDR cancellations are handled by the Runner (invoked via prefect flow-run execute, the default command) so no need to worry about it in the worker. The worker is responsible for spinning up the flow run execution environment (usually a container of some kind) and watching that for unexpected crashes. The Runner executes inside of that container and then launches the flow run in an adjacent process, while monitoring for cancellation to kill the process and let the execution environment gracefully teardown.
s
Ah fantastic, that does simplify my life a fair amount! Thanks mate!
🙌 1
@Jake Kaplan perhaps you can help me out with a follow up. I notice some of the more complex workers (like the k8 one) have both a
WorkerJobConfiguration
and
WorkerVariables
- but both seem to deal with how jobs can be configured. Are you able to disambiguate the two at all and what different purposes they serve?
j
I would check out https://docs.prefect.io/contribute/develop-a-new-worker-type if you havent. JobConfiguration is the pydantic class that is a actually used for configurable of the job. Variables are the default set of values that can be templated into the configuration.