Enqueue enqueues a transaction to the Redis queue. Parameters: - ctx context.Context: The context for the operation. - transaction *model.Transaction: The transaction to be enqueued. Returns: - error: An error if the transaction could not be enqueued.
(ctx context.Context, transaction *model.Transaction)
| 172 | // Returns: |
| 173 | // - error: An error if the transaction could not be enqueued. |
| 174 | func (q *Queue) Enqueue(ctx context.Context, transaction *model.Transaction) error { |
| 175 | ctx, span := tracer.Start(ctx, "Adding Transaction To Redis Queue") |
| 176 | defer span.End() |
| 177 | |
| 178 | payload, err := json.Marshal(transaction) |
| 179 | if err != nil { |
| 180 | return err |
| 181 | } |
| 182 | task := q.geTask(transaction, payload) |
| 183 | _, err = q.Client.EnqueueContext(ctx, task, asynq.MaxRetry(q.config.Queue.MaxRetryAttempts)) |
| 184 | if err != nil { |
| 185 | logrus.WithError(err).WithField("reference", transaction.Reference).Error("failed to enqueue transaction") |
| 186 | return err |
| 187 | } |
| 188 | logrus.WithField("reference", transaction.Reference).Debug("successfully enqueued transaction") |
| 189 | |
| 190 | // Record enqueue metrics. |
| 191 | metrics.QueueEnqueuedTotal.Add(ctx, 1, |
| 192 | otelmetric.WithAttributes(attribute.String("queue_name", task.Type())), |
| 193 | ) |
| 194 | |
| 195 | return nil |
| 196 | } |
| 197 | |
| 198 | // QueueInflightExpiry handles queuing a transaction for inflight expiration. |
| 199 | // This method is separate from the main Enqueue to ensure expiration is handled |