An insert-only client is a River client that inserts jobs but doesn't work them. This is a common pattern where frontend or API processes enqueue work, and a separate pool of worker processes picks it up.
Setup
An insert-only client is simply one that's never started with Start. The Queues and Workers fields are omitted from its config (though Workers may be included for validation as described below)::
insertOnlyClient, err := river.NewClient(riverpgxv5.New(dbPool), &river.Config{})if err != nil { panic(err)}That's it. The client is ready to insert jobs with Insert or InsertTx:
_, err = insertOnlyClient.InsertTx(ctx, tx, SortArgs{ Strings: []string{ "whale", "tiger", "bear", },}, nil)if err != nil { panic(err)} Keeping Workers for validation
Although not required, configuring Workers on an insert-only client lets it validate that inserted jobs have a registered worker. This catches misconfigurations early rather than at work time:
workers := river.NewWorkers()river.AddWorker(workers, &MyWorker{})
insertOnlyClient, err := river.NewClient(riverpgxv5.New(dbPool), &river.Config{ Workers: workers,})What doesn't run
Along with not working jobs, an insert-only client doesn't participate in leader election, doesn't run periodic jobs, and doesn't execute any maintenance services. It wraps a database pool to make it possible to insert jobs, but does little else.