First workflow implementation
This commit is contained in:
+20
-2
@@ -360,8 +360,25 @@ func (q *GeneralQueue) claimNextPendingJob(ctx context.Context) (*ent.GeneralQue
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type EnqueueParams struct {
|
||||
WorkflowId string
|
||||
}
|
||||
|
||||
type EnqueueOption func(p *EnqueueParams)
|
||||
|
||||
func WithWorkflowId(id string) EnqueueOption {
|
||||
return func(q *EnqueueParams) {
|
||||
q.WorkflowId = id
|
||||
}
|
||||
}
|
||||
|
||||
// Enqueue adds a new job to the queue
|
||||
func (q *GeneralQueue) Enqueue(ctx context.Context, payload any, maxRetries int, userId int) (*ent.GeneralQueue, error) {
|
||||
func (q *GeneralQueue) Enqueue(ctx context.Context, payload any, maxRetries int, userId int, options ...EnqueueOption) (*ent.GeneralQueue, error) {
|
||||
params := EnqueueParams{}
|
||||
for _, option := range options {
|
||||
option(¶ms)
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
|
||||
payloadMap, err := StructToMap(payload)
|
||||
@@ -378,7 +395,8 @@ func (q *GeneralQueue) Enqueue(ctx context.Context, payload any, maxRetries int,
|
||||
SetMaxRetries(maxRetries).
|
||||
SetCreatedAt(now).
|
||||
SetUpdatedAt(now).
|
||||
SetUserID(userId)
|
||||
SetUserID(userId).
|
||||
SetWorkflowID(params.WorkflowId)
|
||||
|
||||
job, err := create.Save(ctx)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user