mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-11-24 23:06:47 +01:00
Mohammed Sohail
cf1f9f34c3
* fallback to custom ethereum checksum validator -> https://github.com/go-playground/validator/issues/1073 * decouple jetsream emitter to separate package * refactor task handlers into individual files * add error handler for echo to capture unexpected errors and log them * move handler dependencies into single struct container -> custodialContainer * replace signer to use EIP 1559 signer -> celoutils v1 * Add 1 minutes timeout to all custodial tasks
52 lines
960 B
Go
52 lines
960 B
Go
package tasker
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/grassrootseconomics/cic-custodial/pkg/redis"
|
|
"github.com/hibiken/asynq"
|
|
)
|
|
|
|
const (
|
|
taskTimeout = 60
|
|
)
|
|
|
|
type TaskerClientOpts struct {
|
|
RedisPool *redis.RedisPool
|
|
TaskRetention time.Duration
|
|
}
|
|
|
|
type TaskerClient struct {
|
|
Client *asynq.Client
|
|
taskRetention time.Duration
|
|
}
|
|
|
|
func NewTaskerClient(o TaskerClientOpts) *TaskerClient {
|
|
return &TaskerClient{
|
|
Client: asynq.NewClient(o.RedisPool),
|
|
}
|
|
}
|
|
|
|
func (c *TaskerClient) CreateTask(taskName TaskName, queueName QueueName, task *Task) (*asynq.TaskInfo, error) {
|
|
if task.Id == "" {
|
|
task.Id = uuid.NewString()
|
|
}
|
|
|
|
qTask := asynq.NewTask(
|
|
string(taskName),
|
|
task.Payload,
|
|
asynq.Queue(string(queueName)),
|
|
asynq.TaskID(task.Id),
|
|
asynq.Retention(c.taskRetention),
|
|
asynq.Timeout(taskTimeout*time.Second),
|
|
)
|
|
|
|
taskInfo, err := c.Client.Enqueue(qTask)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return taskInfo, nil
|
|
}
|