Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CreateUnloggedQueue #27

Merged
merged 1 commit into from
Oct 19, 2023
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
12 changes: 12 additions & 0 deletions pgmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ func (p *PGMQ) CreateQueue(ctx context.Context, queue string) error {
return nil
}

// CreateUnloggedQueue creates a new unlogged queue, which uses an unlogged
// table under the hood. This sets up the queue's tables, indexes, and
// metadata.
func (p *PGMQ) CreateUnloggedQueue(ctx context.Context, queue string) error {
_, err := p.db.Exec(ctx, "SELECT pgmq.create_unlogged($1)", queue)
if err != nil {
return wrapPostgresError(err)
}

return nil
}

// DropQueue deletes the given queue. It deletes the queue's tables, indices,
// and metadata. It will return an error if the queue does not exist.
func (p *PGMQ) DropQueue(ctx context.Context, queue string) error {
Expand Down
19 changes: 18 additions & 1 deletion pgmq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

func TestDropQueue(t *testing.T) {
func TestCreateAndDropQueue(t *testing.T) {
ctx := context.Background()
queue := t.Name()

Expand All @@ -91,6 +91,23 @@ func TestDropQueueWhichDoesNotExist(t *testing.T) {
require.Error(t, err)
}

func TestCreateUnloggedAndDropQueue(t *testing.T) {
ctx := context.Background()
queue := t.Name()

err := q.CreateUnloggedQueue(ctx, queue)
require.NoError(t, err)

_, err = q.Send(ctx, queue, testMsg1)
require.NoError(t, err)

err = q.DropQueue(ctx, queue)
require.NoError(t, err)

_, err = q.Send(ctx, queue, testMsg1)
require.Error(t, err)
}

func TestSend(t *testing.T) {
ctx := context.Background()
queue := t.Name()
Expand Down