This specification outlines the procedure for adding a job to a Redis database. It includes generating unique identifiers, managing parent-child relationships, scheduling jobs, and error handling.
- Context (
ctx
): An execution context that supports cancellation and deadlines. - Job (
job
): A data structure representing a job, which includes:Uuid
: A unique identifier. It must be generated if absent.ParentUuid
: Identifier for the parent job (optional).PredecessorUuid
: Identifier for the job's predecessor (optional).RunAt
: Timestamp indicating when the job should run (optional).Queue
: Name of the queue to which the job should be added.
- DeadParent (
deadParent
): A boolean indicating if the job's parent is "dead".
- Error: Indicates a failure to add the job, with details on the reason.
-
Validation:
- Return an error if
job
isnil
. - Generate and assign a new UUID to
job.Uuid
if it's empty.
- Return an error if
-
Marshalling:
- Convert
job
to a byte representation using the wire protobuf format. Return an error on failure, indicating marshalling issues.
- Convert
-
Parent-Child Relationship Handling:
- If
job.ParentUuid
is not empty anddeadParent
isfalse
, add the job to the parent's children list. See Adding job to Parent for details. Retrun an error if this fails, detailing the issue, or nil. - If
job.PredecessorUuid
is not empty anddeadParent
isfalse
, add the job to the predecessor's onComplete list. See Adding job to Predecessor for details. Return an error if this fails, detailing the issue, or nil.
- If
-
Scheduling:
- If
job.RunAt
is set and in the future, schedule the job in a sorted set with a score based on the timestamp. See Scheduling Jobs for details. Return an error if this fails, detailing the issue, or nil.
- If
-
Dead Parent Handling:
- If
job.ParentUuid
is not empty, at this point we know that the parent is dead. Add the job's UUID to a set for tracking children of dead parents. Do not return unless this errors. See Dead Parent Handling for details.
- If
-
Queue Addition:
- Add the marshalled job to the specified queue. Return an error if this fails, detailing the issue.
- Define specific errors for invalid inputs, marshalling failures, and Redis operation errors, each with descriptive messaging for troubleshooting.
- Establish a consistent naming convention for keys related to children lists, onComplete lists, scheduled jobs, and children sets.
- Ensure thread safety and context propagation for cancellation and timeouts.
- Familiarity with Redis commands like
LPush
,ZAdd
, andSAdd
is assumed. - Distinguish between critical errors and recoverable ones in error handling.
This specification outlines the procedure for adding a job to a parent job. It includes managing parent-child relationships, scheduling jobs, and error handling.
- Context (
ctx
): An execution context that supports cancellation and deadlines. - Job (
job
): A data structure representing a job, which includes:Uuid
: A unique identifier. It must be generated if absent.ParentUuid
: Identifier for the parent job (required).PredecessorUuid
: Identifier for the job's predecessor (optional).RunAt
: Timestamp indicating when the job should run (optional).Queue
: Name of the queue to which the job should be added.
- Error: Indicates a failure to add the job, with details on the reason.
- Validation:
- Return an error if
job
isnil
. - Generate and assign a new UUID to
job.Uuid
if it's empty.
- Return an error if
- Marshalling:
- Convert
job
to a byte representation using the wire protobuf format. Return an error on failure, indicating marshalling issues.
- Convert
- Redis
- Add the marshalled job to the
childrenListKey
for the parent job. Return an error if this fails, detailing the issue.
- Add the marshalled job to the
- Define specific errors for invalid inputs, marshalling failures, and Redis operation errors, each with descriptive messaging for troubleshooting.
This specification outlines the procedure for adding a job to a predecessor. It includes managing parent-child relationships, scheduling jobs, and error handling.
- Context (
ctx
): An execution context that supports cancellation and deadlines. - SerializedJob (
job
): A byte representation of a job, which includes:Uuid
: A unique identifier. It must be generated if absent.PredecessorUuid
: Identifier for the job's predecessor (required).RunAt
: Timestamp indicating when the job should run (optional).Queue
: Name of the queue to which the job should be added.
- PredecessorUuid (
predecessorUuid
): Identifier for the job's predecessor (required).
- Error: Indicates a failure to add the job, with details on the reason.
- Redis
- Add the marshalled job to the
onCompleteListKey
for the predecessor uuid. Return an error if this fails, detailing the issue.
- Add the marshalled job to the
This specification outlines the procedure for scheduling a job. It includes managing scheduled jobs, and error handling.
- Context (
ctx
): An execution context that supports cancellation and deadlines. - SerializedJob (
job
): A byte representation of a job, which includes:Uuid
: A unique identifier. It must be generated if absent.RunAt
: Timestamp indicating when the job should run (required).Queue
: Name of the queue to which the job should be added.
- RunAt (
runAt
): Timestamp indicating when the job should run (required).
- Error: Indicates a failure to add the job, with details on the reason.
- Redis
- Add the marshalled job to the
scheduledJobsKey
. Usins the ZAdd command. The Score is the float value ofrunAt
in epoch seconds. The Member is the marshalled job. Return an error if this fails, detailing the issue.
- Add the marshalled job to the
This specification outlines the procedure for handling a job that is enqueue with a dead parent-child
- Context (
ctx
): An execution context that supports cancellation and deadlines. - SerializedJob (
job
): A byte representation of a job, which includes:Uuid
: A unique identifier. It must be generated if absent.ParentUuid
: Identifier for the parent job (required).Queue
: Name of the queue to which the job should be added.
- ParentUuid (
parentUuid
): Identifier for the parent job (required).
- Error: Indicates a failure to add the job, with details on the reason.
- Redis
- Add the marshalled job to the
childrenSetKey
for the parent job usind Sadd the key is the job's uuid. Return an error if this fails, detailing the issue.
- Add the marshalled job to the
This specification outlines the procedure for pushing a job to a queue. It includes managing scheduled jobs, and error handling.
- Context (
ctx
): An execution context that supports cancellation and deadlines. - SerializedJob (
job
): A byte representation of a job, which includes:Uuid
: A unique identifier. It must be generated if absent.Queue
: Name of the queue to which the job should be added.
- Queue (
queue
): Name of the queue to which the job should be added.
- Error: Indicates a failure to add the job, with details on the reason.
- Redis
- Add the marshalled job to the
queue
key using LPush. Return an error if this fails, detailing the issue.
- Add the marshalled job to the
This is the list of scheduled jobs.
Object type: List
Key: scheduled
This is the key for the job. The value is the serialized job.
Object type: String
Key: jobs:{uuid}
This is the list of jobs that are children of the parent job.
Object type: List
Key: jobs:{parent uuid}:children
These are the active children jobs for a given parent job.
Object type: Set
Key: jobs:{parent uuid}:active
Key: jobs:{parent uuid}:onComplete