queueIndexData enqueues a task to index data in a specified collection. Parameters: - id string: The ID of the data to index. - collection string: The name of the collection to index the data in. - data interface{}: The data to be indexed. Returns: - error: An error if the task could not be enqueu
(id string, collection string, data interface{})
| 138 | // Returns: |
| 139 | // - error: An error if the task could not be enqueued. |
| 140 | func (q *Queue) queueIndexData(id string, collection string, data interface{}) error { |
| 141 | if q.config.TypeSense.Dns == "" { |
| 142 | return nil |
| 143 | } |
| 144 | |
| 145 | payload := map[string]interface{}{ |
| 146 | "collection": collection, |
| 147 | "payload": data, |
| 148 | } |
| 149 | |
| 150 | IPayload, err := json.Marshal(payload) |
| 151 | if err != nil { |
| 152 | return err |
| 153 | } |
| 154 | |
| 155 | taskOptions := []asynq.Option{asynq.Queue(q.config.Queue.IndexQueue)} |
| 156 | task := asynq.NewTask(q.config.Queue.IndexQueue, IPayload, taskOptions...) |
| 157 | _, err = q.Client.Enqueue(task) |
| 158 | if err != nil { |
| 159 | logrus.WithError(err).WithField("id", id).Error("failed to enqueue index data") |
| 160 | return err |
| 161 | } |
| 162 | logrus.WithField("id", id).Debug("successfully enqueued index data") |
| 163 | return nil |
| 164 | } |
| 165 | |
| 166 | // Enqueue enqueues a transaction to the Redis queue. |
| 167 | // |
no test coverage detected