Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/worker/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
)

var (
ErrJobExists = errors.New("job with id exists")
ErrInvalidJob = errors.New("job is not valid")
ErrKindExists = errors.New("handler for given kind exists")
ErrUnknownKind = errors.New("job kind is invalid")
Expand Down
6 changes: 5 additions & 1 deletion pkg/worker/pgq/pgq.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

sq "github.com/Masterminds/squirrel"
_ "github.com/lib/pq" // postgres driver.
"github.com/lib/pq"

"github.com/odpf/entropy/pkg/errors"
"github.com/odpf/entropy/pkg/worker"
Expand Down Expand Up @@ -86,6 +86,10 @@ func (q *Queue) Enqueue(ctx context.Context, jobs ...worker.Job) error {

_, err := insertQuery.RunWith(q.db).PlaceholderFormat(sq.Dollar).ExecContext(ctx)
if err != nil {
pqErr := &pq.Error{}
if errors.As(err, &pqErr) && pqErr.Code.Name() == "unique_violation" {
return worker.ErrJobExists
}
return err
}
return nil
Expand Down