MCPcopy
hub / github.com/riverqueue/river / Example_jobArgsHooks

Function Example_jobArgsHooks

example_job_args_hooks_test.go:78–126  ·  view source on GitHub ↗

Example_jobArgsHooks demonstrates the use of hooks to modify River behavior.

()

Source from the content-addressed store, hash-verified

76
77// Example_jobArgsHooks demonstrates the use of hooks to modify River behavior.
78func Example_jobArgsHooks() {
79 ctx := context.Background()
80
81 dbPool, err := pgxpool.New(ctx, riversharedtest.TestDatabaseURL())
82 if err != nil {
83 panic(err)
84 }
85 defer dbPool.Close()
86
87 workers := river.NewWorkers()
88 river.AddWorker(workers, &JobWithHooksWorker{})
89
90 riverClient, err := river.NewClient(riverpgxv5.New(dbPool), initTestConfig(ctx, dbPool, &river.Config{
91 Queues: map[string]river.QueueConfig{
92 river.QueueDefault: {MaxWorkers: 100},
93 },
94 Workers: workers,
95 }))
96 if err != nil {
97 panic(err)
98 }
99
100 // Out of example scope, but used to wait until a job is worked.
101 subscribeChan, subscribeCancel := riverClient.Subscribe(river.EventKindJobCompleted)
102 defer subscribeCancel()
103
104 if err := riverClient.Start(ctx); err != nil {
105 panic(err)
106 }
107
108 _, err = riverClient.Insert(ctx, JobWithHooksArgs{}, nil)
109 if err != nil {
110 panic(err)
111 }
112
113 // Wait for jobs to complete. Only needed for purposes of the example test.
114 riversharedtest.WaitOrTimeoutN(testutil.PanicTB(), subscribeChan, 1)
115
116 if err := riverClient.Stop(ctx); err != nil {
117 panic(err)
118 }
119
120 // Output:
121 // JobWithHooksInsertAndWorkBeginHook.InsertBegin ran
122 // JobWithHooksInsertBeginHook.InsertBegin ran
123 // JobWithHooksInsertAndWorkBeginHook.WorkBegin ran
124 // JobWithHooksWorkBeginHook.WorkBegin ran
125 // JobWithHooksWorker.Work ran
126}

Callers

nothing calls this directly

Calls 13

TestDatabaseURLFunction · 0.92
NewWorkersFunction · 0.92
AddWorkerFunction · 0.92
NewClientFunction · 0.92
NewFunction · 0.92
WaitOrTimeoutNFunction · 0.92
PanicTBFunction · 0.92
SubscribeMethod · 0.80
InsertMethod · 0.80
initTestConfigFunction · 0.70
CloseMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…