MCPcopy Create free account
hub / github.com/dataddo/pgq / ExampleConsumer

Function ExampleConsumer

example_consumer_test.go:50–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48}
49
50func ExampleConsumer() {
51 db, err := sql.Open("postgres", "user=postgres password=postgres host=localhost port=5432 dbname=postgres")
52 if err != nil {
53 log.Fatal("Error opening database:", err)
54 }
55 defer db.Close()
56 const queueName = "test_queue"
57 c, err := pgq.NewConsumer(db, queueName, &Handler{})
58 if err != nil {
59 log.Fatal("Error creating consumer:", err)
60 }
61 ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt)
62 if err := c.Run(ctx); err != nil && !errors.Is(err, context.Canceled) {
63 log.Fatal("Error running consumer:", err)
64 }
65}

Callers

nothing calls this directly

Calls 3

RunMethod · 0.95
NewConsumerFunction · 0.92
FatalMethod · 0.65

Tested by

no test coverage detected