| 139 | } |
| 140 | |
| 141 | func makeAwaitWorker[T JobArgs](startedCh chan<- int64, doneCh chan struct{}) Worker[T] { |
| 142 | return WorkFunc(func(ctx context.Context, job *Job[T]) error { |
| 143 | client := ClientFromContext[pgx.Tx](ctx) |
| 144 | client.config.Logger.InfoContext(ctx, "callback job started with id="+strconv.FormatInt(job.ID, 10)) |
| 145 | |
| 146 | select { |
| 147 | case <-ctx.Done(): |
| 148 | return ctx.Err() |
| 149 | case startedCh <- job.ID: |
| 150 | } |
| 151 | |
| 152 | // await done signal, or context cancellation: |
| 153 | select { |
| 154 | case <-ctx.Done(): |
| 155 | return ctx.Err() |
| 156 | case <-doneCh: |
| 157 | return nil |
| 158 | } |
| 159 | }) |
| 160 | } |
| 161 | |
| 162 | // A small wrapper around Client that gives us a struct that corrects the |
| 163 | // client's Stop function so that it can implement startstop.Service. |