maragudk / goqite

Go queue library built on SQLite and inspired by AWS SQS.
https://www.goqite.com
MIT License
417 stars 12 forks source link

Delete does not error when message id does not exist #58

Open retr0h opened 3 weeks ago

retr0h commented 3 weeks ago

Code

Minimal reproducible example:

package main

import (
        "context"
        "database/sql"
        "log"

        _ "github.com/mattn/go-sqlite3"

        "github.com/maragudk/goqite"
)

func main() {
        db, err := sql.Open("sqlite3", ":memory:?_journal=WAL&_timeout=5000&_fk=true")
        if err != nil {
                log.Fatalln(err)
        }
        db.SetMaxOpenConns(1)
        db.SetMaxIdleConns(1)

        if err := goqite.Setup(context.Background(), db); err != nil {
                log.Fatalln(err)
        }

        // Create a new queue named "jobs".
        // You can also customize the message redelivery timeout and maximum receive count,
        // but here, we use the defaults.
        q := goqite.New(goqite.NewOpts{
                DB:   db,
                Name: "jobs",
        })

        m := goqite.ID("invalid")

        if err := q.Delete(context.Background(), m); err != nil {
                log.Fatalln(err)
        }
}

Result

No error

❯ go run main.go

~/test
markuswustenberg commented 3 weeks ago

Hi @retr0h , thank you for the issue!

This is more of a design decision, not a bug. On one hand, it can be nice to know if a message has already been deleted. On another, it's also nice that Delete is idempotent. I'm leaning towards the latter.