maragudk / goqite

Go queue library built on SQLite and inspired by AWS SQS.
https://maragudk.github.io/goqite/
MIT License
435 stars 13 forks source link

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

Closed retr0h closed 1 month ago

retr0h commented 2 months 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 2 months 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.

retr0h commented 1 month ago

All good, ended up switching over to NATS JetStream.