Go API documentation
github.com/rotari-dev/rotari/internal/joblist
Overview
package joblist // import "github.com/rotari-dev/rotari/internal/joblist"
Package joblist lists recent job attempts across a base directory's projects:
running jobs of active runs and jobs that finished within a time window.
`rotari jobs` and the Web UI's jobs page share it. Row status comes from
internal/jobstatus; this package decides which attempts are listed and in what
order, and how their times read. Column selection and table layout belong to the
callers.
Constants
const (
// DefaultSince is the listing window when none is given.
DefaultSince = 24 * time.Hour
// DefaultSinceText is DefaultSince as users write it.
DefaultSinceText = "1d"
)
Functions
func FormatElapsed(value time.Duration) string
FormatElapsed formats a duration as "42s", "3m 05s", or "2h 07m", and a
negative one as "-".
func FormatLocalTimestamp(value time.Time) string
FormatLocalTimestamp is FormatTimestamp without the time zone.
func FormatRunTime(runTime jobstatus.RunTime) string
FormatRunTime formats a job's elapsed time and, while it runs, how long ago
it last wrote output: "12m 03s, quiet 11m 58s", or "12m 03s, no output" when
it has written none.
func FormatTimestamp(value time.Time) string
FormatTimestamp formats a listing time in time.Local with the zone name,
matching the other web pages.
func ParseSince(value string) (time.Duration, error)
ParseSince parses a listing window: a Go duration such as "24h" or "90m",
or a whole number of days such as "7d", which Go durations lack. Empty means
DefaultSince.
func Projects(baseDir, requested string) ([]string, error)
Projects returns requested, or every project in baseDir sorted by name,
or the default project when baseDir has none.
func ShortenText(value string, maxLength int) string
ShortenText cuts value to maxLength bytes, ending with "..." when maxLength
leaves room for it.
func Sort(rows []Row)
Sort orders rows by finish time, or start time for unfinished jobs, newest
first. A row without either, such as a pending job, is listed right after
the newest row of its run, so a run's jobs stay together.
Types
type Interval struct {
Start time.Time
End time.Time
}
Interval is a span of finish times from Start up to, but not including, End.
A zero End leaves the span open.
type Row struct {
State string
BaseDir string
Project string
RunID string
JobID string
AttemptID string
JobName string
Command string
FullCommand string
StartedAt time.Time
FinishedAt time.Time
jobstatus.RunTime
}
Row is one job in the listing: an unfinished attempt of an active or
interrupted run, a job of such a run that has not started (with no
AttemptID), or a job that finished inside the window.
func Collect(store state.Store, baseDir string, projects []string, now time.Time, window time.Duration) ([]Row, error)
Collect lists unfinished attempts and jobs of projects in baseDir
that finished within window before now. Each job's status follows the
internal/jobstatus fallback chain.
func CollectFinishedIn(store state.Store, baseDir string, projects []string, now time.Time, spans []Interval) ([]Row, error)
CollectFinishedIn is Collect for jobs that finished inside any of spans
rather than one window before now. Unfinished jobs are listed regardless.