MCPcopy Index your code
hub / github.com/riverqueue/river / JobCancel

Method JobCancel

riverdriver/riversqlite/river_sqlite_driver.go:251–287  ·  view source on GitHub ↗
(ctx context.Context, params *riverdriver.JobCancelParams)

Source from the content-addressed store, hash-verified

249}
250
251func (e *Executor) JobCancel(ctx context.Context, params *riverdriver.JobCancelParams) (*rivertype.JobRow, error) {
252 // Unlike Postgres, this must be carried out in two operations because
253 // SQLite doesn't support CTEs containing `UPDATE`. As long as the job
254 // exists and is not running, only one database operation is needed, but if
255 // the initial update comes back empty, it does one more fetch to return the
256 // most appropriate error.
257 return dbutil.WithTxV(ctx, e, func(ctx context.Context, execTx riverdriver.ExecutorTx) (*rivertype.JobRow, error) { // TODO
258 dbtx := templateReplaceWrapper{dbtx: e.driver.UnwrapTx(execTx), replacer: &e.driver.replacer}
259
260 cancelledAt, err := params.CancelAttemptedAt.UTC().MarshalJSON()
261 if err != nil {
262 return nil, err
263 }
264 cancelledAt = cancelledAt[1 : len(cancelledAt)-1] // remove quotes around the time so we don't end up with doubled up quotes
265
266 job, err := dbsqlc.New().JobCancel(schemaTemplateParam(ctx, params.Schema), dbtx, &dbsqlc.JobCancelParams{
267 ID: params.ID,
268 CancelAttemptedAt: string(cancelledAt),
269 Now: timeStringNullable(params.Now),
270 })
271 if err != nil {
272 if errors.Is(err, sql.ErrNoRows) {
273 job, err := execTx.JobGetByID(ctx, &riverdriver.JobGetByIDParams{
274 ID: params.ID,
275 Schema: params.Schema,
276 })
277 if err != nil {
278 return nil, interpretError(err)
279 }
280 return job, nil
281 }
282
283 return nil, interpretError(err)
284 }
285 return jobRowFromInternal(job)
286 })
287}
288
289func (e *Executor) JobCountByAllStates(ctx context.Context, params *riverdriver.JobCountByAllStatesParams) (map[rivertype.JobState]int, error) {
290 counts, err := dbsqlc.New().JobCountByAllStates(schemaTemplateParam(ctx, params.Schema), e.dbtx)

Callers

nothing calls this directly

Implementers 3

Executorriverdriver/riverpgxv5/river_pgx_v5_dr
Executorriverdriver/riverdatabasesql/river_dat
Executorriverdriver/riversqlite/river_sqlite_d

Calls 11

WithTxVFunction · 0.92
NewFunction · 0.92
timeStringNullableFunction · 0.85
MarshalJSONMethod · 0.80
schemaTemplateParamFunction · 0.70
interpretErrorFunction · 0.70
jobRowFromInternalFunction · 0.70
UnwrapTxMethod · 0.65
JobCancelMethod · 0.65
JobGetByIDMethod · 0.65
IsMethod · 0.45

Tested by

no test coverage detected