func (jq *JobQueueBinding) TrySteal(ctx scope.Context, handlerID string) (*jobs.Job, error) { var row JobItem cols, err := allColumns(jq.Backend.DbMap, JobItem{}, "") if err != nil { return nil, err } err = jq.Backend.DbMap.SelectOne(&row, fmt.Sprintf("SELECT %s FROM job_steal($1, $2)", cols), jq.Name(), handlerID) if err != nil { if err == sql.ErrNoRows { return nil, jobs.ErrJobNotFound } return nil, err } job := &jobs.Job{ ID: snowflake.Snowflake(row.ID), Type: jobs.JobType(row.JobType), Data: json.RawMessage(row.Data), Created: row.Created, Due: row.Due, MaxWorkDuration: time.Duration(row.MaxWorkDurationSeconds) * time.Second, AttemptsMade: row.AttemptsMade, AttemptsRemaining: row.AttemptsRemaining - 1, JobClaim: &jobs.JobClaim{ JobID: snowflake.Snowflake(row.ID), HandlerID: handlerID, AttemptNumber: row.AttemptsMade + 1, Queue: jq, }, } return job, nil }
func (e *Email) ToBackend() (*emails.EmailRef, error) { ref := &emails.EmailRef{ ID: e.ID, JobID: snowflake.Snowflake(e.JobID), EmailType: e.EmailType, SendTo: e.SendTo, SendFrom: e.SendFrom, Message: e.Message, Created: e.Created, } if err := ref.AccountID.FromString(e.AccountID); err != nil { return nil, err } if e.Delivered.Valid { ref.Delivered = e.Delivered.Time } if e.Failed.Valid { ref.Failed = e.Failed.Time } return ref, nil }