Files
threshold/internal/scheduler/job/doc.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.7 KiB
Go
Raw Normal View History

2021-05-06 14:54:10 -07:00
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
2023-02-02 17:15:17 -08:00
2021-05-06 14:54:10 -07:00
// Package job provides a Job and a Run struct suitable for persisting to
// the repository.
//
// A Job represents work that should be run at a predetermined time and needs to be synchronized
// across servers to ensure that one and only one instance of a job is running at any given time.
// The job's name must be unique to the plugin that registered the job, the (plugin_id, name)
// uniqueness is enforced by the database.
//
// A Run represents a single execution of a job, only a single run can be in a
// running state for a specific job. The private_id (primary key) is generated by the
// repository during RunJobs.
//
2022-08-25 09:12:24 -07:00
// # Repository
2021-05-06 14:54:10 -07:00
//
// A repository provides methods for creating, updating, retrieving, and
// deleting Jobs. It also provides methods to run jobs, update progress of runs
// and complete, fail or interrupt runs.
// A new repository should be created for each transaction. For example:
//
2022-08-25 09:12:24 -07:00
// var wrapper wrapping.Wrapper
// ... init wrapper ...
2021-05-06 14:54:10 -07:00
//
2022-08-25 09:12:24 -07:00
// // db implements both the reader and writer interfaces.
// db, _ := db.Open(db.Postgres, url)
2021-05-06 14:54:10 -07:00
//
2022-08-25 09:12:24 -07:00
// var repo *job.Repository
// repo, _ = job.NewRepository(db, db, wrapper)
2021-05-06 14:54:10 -07:00
//
2022-08-25 09:12:24 -07:00
// var j *job.Job
// j, _ = repo.UpsertJob(context.Background(), j, "name", "description")
2021-05-06 14:54:10 -07:00
//
2022-08-25 09:12:24 -07:00
// var runs []*Run
// repo, _ = job.NewRepository(db, db, wrapper)
// runs, _ = repo.RunJobs(context.Background(), "serverId")
2021-05-06 14:54:10 -07:00
//
2022-08-25 09:12:24 -07:00
// ... run job ...
2021-05-06 14:54:10 -07:00
//
2022-08-25 09:12:24 -07:00
// var run *Run
// repo, _ = job.NewRepository(db, db, wrapper)
// run, _ = repo.UpdateProgress(ctx, run, []string{"TotalCount", "CompletedCount"})
2021-05-06 14:54:10 -07:00
//
2022-08-25 09:12:24 -07:00
// nextJobRun = time.Now().Add(time.Hour)
2021-05-06 14:54:10 -07:00
//
2022-08-25 09:12:24 -07:00
// repo, _ = job.NewRepository(db, db, wrapper)
// _ = repo.CompleteRun(ctx, run.PrivateId nextJobRun)
2021-05-06 14:54:10 -07:00
package job