Skip to content

Commit

Permalink
Add CreateUnloggedQueue (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Pastro authored Oct 19, 2023
1 parent 0aa84af commit 292d669
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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

0 comments on commit 292d669

Please sign in to comment.