First workflow implementation

This commit is contained in:
Achim Rohn
2026-03-21 16:11:24 +00:00
parent a15ca501b8
commit 413dbb72cf
13 changed files with 457 additions and 13 deletions
+20 -2
View File
@@ -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(&params)
}
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)