diff --git a/worker/worker.go b/worker/worker.go index 744ac2d..9bd7a92 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -33,3 +33,17 @@ func NewWorker(workerID int64) *Worker { logger: logger, } } + +// SetContext sets the context for the worker. This method is used to provide +// a new context for the worker, which can be used to control its operations +// and manage its lifecycle. The method ensures that the provided context is not +// nil before setting it, maintaining the integrity of the worker's context. +func (w *Worker) SetContext(ctx context.Context) { + // Check if the provided context is not nil. + // This ensures that we only set a valid context for the worker. + if ctx != nil { + // Set the worker's context to the provided context. + // This allows the worker to use the new context for its operations. + w.workerContext = ctx + } +}