schedule

package
v0.7.54 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package schedule keeps the schedules of runs on this computer: when a QuickAgent runs again, the store that is the truth about it, the record of every occurrence, and the operating system's own entries that wake `agentry schedule fire` at the right moments.

A schedule's repeat is a small struct, never cron text, so one type compiles to every system's trigger and to the times a calendar shows. Times are wall-clock in a named zone: "9am" stays 9am across a daylight saving change.

Index

Constants

View Source
const CredentialFile = "keys.cred"

CredentialFile is a signed-out schedule's encrypted credential, in its folder in the store.

View Source
const MinSystemd = 256

MinSystemd is the oldest systemd whose `systemd-creds encrypt --user` seals a credential to one user, which a user manager can then load.

Variables

View Source
var EncryptCredential = func(name string, plaintext []byte, out string) error {
	cmd := exec.Command("systemd-creds", "encrypt", "--user", "--name="+name, "-", out)
	cmd.Stdin = bytes.NewReader(plaintext)
	if b, err := cmd.CombinedOutput(); err != nil {
		return fmt.Errorf("systemd-creds encrypt --user: %v: %s", err, strings.TrimSpace(string(b)))
	}
	return nil
}

EncryptCredential runs `systemd-creds encrypt --user`, handing it the plaintext on its stdin (never an argument, never a file in the clear); replaced in tests.

View Source
var ErrNotFound = errors.New("no such schedule")

ErrNotFound is a schedule the store does not hold.

View Source
var ErrSignedOutUnsupported = errors.New("running while signed out is not available here: Docker Desktop stops when you sign out")

ErrSignedOutUnsupported is the system's reason a schedule cannot run while its person is signed out.

View Source
var ErrUnsupported = errors.New("scheduling runs on this computer is not available on this system yet")

ErrUnsupported is a system this build has no alarm for yet.

View Source
var SystemdVersion = func() (int, error) {
	out, err := exec.Command("systemctl", "--version").Output()
	if err != nil {
		return 0, fmt.Errorf("systemctl --version: %w", err)
	}
	return parseSystemdVersion(string(out))
}

SystemdVersion is the running systemd's version; replaced in tests.

Functions

func Due

func Due(r Recurrence, st State, now time.Time) (run time.Time, missed []time.Time)

Due is what a fire at now should do: run the latest occurrence that fell due since the last one handled, and record every earlier one as missed (a missed occurrence runs once at the next chance, if that comes before the following occurrence). run is zero when nothing is due.

func LaunchAgentPlist

func LaunchAgentPlist(sc Schedule, e Entry, loc *time.Location, now time.Time) ([]byte, error)

LaunchAgentPlist is sc's LaunchAgent, as XML.

func LocalZone

func LocalZone() string

LocalZone is this computer's IANA zone name, the default for a new schedule: $TZ, else the zone /etc/localtime links to (Linux, macOS), else the one Windows is set to, else UTC. Go's time.Local is named "Local", which no other system can read back.

func OnCalendar

func OnCalendar(r Recurrence, now time.Time) ([]string, error)

OnCalendar is r as systemd calendar expressions in r's zone. They ring on every occurrence, and for a month day past the 28th on every day from the 28th on, which fire narrows to the month's own day (a month without the 31st runs on its last day). The end of a repeat is fire's.

systemd does not ring at a wall time the spring change skips (checked with systemd-analyze 259: 02:30 New York on 2027-03-14 never elapses), where the schedule's rule runs the occurrence at the first valid minute after it. Each such occurrence in the three years from now gets a one-off ring of its own at that instant, in UTC; every sync and every add or edit writes them afresh.

func ParseDays

func ParseDays(s string) ([]string, error)

ParseDays reads a comma-separated list of day names ("tue,thu", "Tuesday, Thursday") into the sorted, de-duplicated form Days keeps.

func SealAccounts

func SealAccounts(pol *policy.Policy) (required, optional []string)

SealAccounts are the keychain accounts a fire under pol reads: the model key's, required, when the policy takes it from the keychain (an adapter's own block may say so where the model's does not), and the person's own provider keys the policy takes from the keychain (AI Review's, the search provider's, Hybrid Analysis's), optional, as a run signed in goes on without one the keychain does not hold.

func SealCredential

func SealCredential(path string, values map[string]string) error

SealCredential encrypts values into path, readable by this user alone: through a temporary file beside it and one rename, so a fire never loads half of one.

func SystemdUnits

func SystemdUnits(sc Schedule, e Entry) (service, timer string, err error)

SystemdUnits is the service and the timer for sc, as text.

func TaskXML

func TaskXML(sc Schedule, e Entry, userSID, conhost string, loc *time.Location, now time.Time) (string, error)

TaskXML is sc's task, as Task Scheduler's XML (before its UTF-16 encoding).

func ValidID

func ValidID(id string) bool

ValidID reports whether id is a schedule id; every path and every OS entry name is built from one, so nothing else may reach them.

Types

type Alarm

type Alarm interface {
	// Name is the system's scheduler, for messages ("systemd user timer").
	Name() string
	// Install writes, or rewrites, the entry for sc.
	Install(sc Schedule, e Entry) error
	// Remove deletes the entry for id; a missing one is not an error.
	Remove(id string) error
	// Installed lists the schedule ids that have an entry.
	Installed() ([]string, error)
	// Probe runs e once now in the context the alarm will run it in (the
	// same user manager, groups and environment) and returns its output,
	// so a schedule is refused when made rather than failing at its first
	// fire: a shell can reach what the scheduler cannot.
	Probe(e Entry) (string, error)
}

Alarm is an operating system's own scheduler, which wakes `agentry schedule fire <id>` when a schedule may be due. It is only an alarm: a fire re-reads the store and decides, so an alarm that rings early, late, twice or for a removed schedule does no harm, and one may ring on a superset of the occurrences when the system cannot say exactly what the schedule means.

func ForThisSystem

func ForThisSystem() (Alarm, error)

ForThisSystem is the alarm for the running system.

type End

type End struct {
	Kind EndKind `yaml:"kind" json:"kind"`
	// On is the last date (YYYY-MM-DD, in the schedule's zone) for EndOn.
	On string `yaml:"on,omitempty" json:"on,omitempty"`
	// After is the number of runs for EndAfter.
	After int `yaml:"after,omitempty" json:"after,omitempty"`
}

End is when a repeat stops. A Once schedule has none.

type EndKind

type EndKind string

EndKind is how a repeat ends.

const (
	// EndNever repeats until the schedule is removed.
	EndNever EndKind = "never"
	// EndOn repeats until a date, that date's occurrence included.
	EndOn EndKind = "on"
	// EndAfter repeats for a number of runs: the store counts the
	// occurrences fire runs (State.Runs), so an occurrence missed or one
	// that fell while the schedule was paused uses none of them.
	EndAfter EndKind = "after"
)

type Entry

type Entry struct {
	// Binary is the absolute path of the agentry that wrote the entry.
	Binary string
	// Args are the arguments after it (schedule fire <id>).
	Args []string
	// Env is KEY=VALUE pairs: PATH and AGENTRY_DOCKER as resolved when the
	// entry was written, so the system's own minimal PATH cannot hide
	// docker (the launchd and Windows first-launch PATH lessons).
	Env []string
	// Credential is a signed-out schedule's encrypted credential, which
	// the unit loads with LoadCredentialEncrypted= (Linux only; the other
	// alarms refuse an entry that names one).
	Credential string
}

Entry is what every alarm runs: Binary with Args, under Env. Env holds paths and names only, never a credential.

type Fire

type Fire struct {
	Occurrence time.Time `json:"occurrence"`
	Outcome    Outcome   `json:"outcome"`
	// Manual marks a Run now, which is no occurrence.
	Manual    bool      `json:"manual,omitempty"`
	Started   time.Time `json:"started,omitzero"`
	Ended     time.Time `json:"ended,omitzero"`
	RunID     string    `json:"runId,omitempty"`
	ExitCode  int       `json:"exitCode"`
	ExitClass string    `json:"exitClass,omitempty"`
	OutDir    string    `json:"outDir,omitempty"`
	Message   string    `json:"message,omitempty"`
}

Fire is the record of one occurrence, one line of fires.ndjson.

type Host

type Host struct {
	// ID is the intake question that asks for it.
	ID string `yaml:"id" json:"id"`
	// Account is the keychain account its sign-in is saved under
	// (host:<user>@<host>:<port>): a name, not a secret.
	Account string `yaml:"account" json:"account"`
	// HostKey is the accepted host key's SHA256 fingerprint.
	HostKey string `yaml:"hostKey" json:"hostKey"`
}

Host is a target host a schedule was made for. A fire reaches it only with the sign-in saved under Account (service agentry) and only if it offers the key HostKey names; anything else refuses the run (exit 11).

type Kind

type Kind string

Kind is the shape of a repeat.

const (
	// Once runs at one date and time.
	Once Kind = "once"
	// Daily runs every day at a time.
	Daily Kind = "daily"
	// Weekdays runs Monday to Friday at a time.
	Weekdays Kind = "weekdays"
	// Weekly runs on chosen days of the week at a time.
	Weekly Kind = "weekly"
	// Monthly runs on one day of the month at a time; a day the month does
	// not have runs on its last day.
	Monthly Kind = "monthly"
)

type Launchd

type Launchd struct {
	// Dir is ~/Library/LaunchAgents.
	Dir string
	// UID is the person's user id, the GUI domain's name.
	UID int
	// Loc is this computer's zone, the one launchd's calendar keeps.
	Loc *time.Location
	// Launchctl runs launchctl with args and returns its output; replaced
	// in tests.
	Launchctl func(args ...string) ([]byte, error)
	// Now is the clock the rings are compiled from; replaced in tests.
	Now func() time.Time
	// Wait is how long Probe waits for its report.
	Wait time.Duration
}

Launchd is the macOS alarm: a LaunchAgent per schedule in the person's own GUI session (gui/<uid>), so the login keychain and Docker Desktop are there, and it rings only while they are signed in. Its StartCalendarInterval keeps local time, so its rings are LocalRingsFor's superset. RunAtLoad rings once at every sign-in, which is the catch-up for an occurrence missed while the Mac was off; one missed while it slept rings at the wake, which launchd coalesces into one.

func NewLaunchd

func NewLaunchd() (*Launchd, error)

NewLaunchd is the alarm for the person running this process.

func (*Launchd) Install

func (l *Launchd) Install(sc Schedule, e Entry) error

Install implements Alarm. An unchanged agent that is loaded is left alone, and a changed one is not reloaded while it runs: bootout would stop the run mid-way. sync, which the desktop runs at every start, writes it once the run is over.

func (*Launchd) Installed

func (l *Launchd) Installed() ([]string, error)

Installed implements Alarm.

func (*Launchd) Name

func (*Launchd) Name() string

Name implements Alarm.

func (*Launchd) Probe

func (l *Launchd) Probe(e Entry) (string, error)

Probe implements Alarm: a one-shot agent in the same GUI session, run at load, removed afterwards.

func (*Launchd) Remove

func (l *Launchd) Remove(id string) error

Remove implements Alarm. The file goes first, so an agent stopped half way is not loaded again at the next sign-in. A running agent is not booted out, since launchd would stop its run before the run is recorded: neither a fire that ends its own schedule nor a pause or a removal made while a run is going. Such an agent stays loaded until the person signs out, ringing a fire that finds the schedule paused, ended or gone and runs nothing.

type Linger

type Linger struct {
	// User is the person's login name.
	User string
	// Dir is where logind keeps a file per lingering user
	// (/var/lib/systemd/linger), which says whether linger is on without
	// asking logind for a user it may not know.
	Dir string
	// Loginctl runs loginctl with args, with in and errOut for polkit's
	// question where the system asks one; replaced in tests.
	Loginctl func(in io.Reader, errOut io.Writer, args ...string) error
}

Linger is the person's systemd linger: on, their user manager starts at boot and stays after they sign out, which is what lets a user timer ring with nobody signed in.

func NewLinger

func NewLinger(user string) *Linger

NewLinger is the linger of user, set through the real loginctl.

func (*Linger) On

func (l *Linger) On() (bool, error)

On reports whether linger is on for the person.

type LocalRing

type LocalRing struct {
	Hour, Minute int
	Weekdays     []time.Weekday
	MonthDays    []int
}

LocalRing rings at Hour:Minute local time on Weekdays (none: every day), or, when MonthDays is set, on those days of every month.

type LocalRings

type LocalRings struct {
	// Repeat rings at a wall time on some days, every week or month.
	Repeat []LocalRing
	// Once rings at these instants: an occurrence whose local wall time
	// is its own (the spring change, a zone whose offset to this
	// computer's moves for a few days), or a schedule that runs once.
	Once []time.Time
}

LocalRings is when a scheduler that keeps only this computer's local time (launchd, Task Scheduler) is to ring for a schedule. Neither can name the schedule's own zone, or the rules for a month's last day and the daylight-saving changes, so the rings are compiled from the schedule's own occurrences: a superset, never fewer, which fire narrows. A ring that comes late still runs its occurrence, since fire runs the latest one due when no later one has fallen due.

func LocalRingsFor

func LocalRingsFor(r Recurrence, loc *time.Location, now time.Time) (LocalRings, error)

LocalRingsFor compiles r into rings in loc from now on.

func (LocalRings) RingsAt

func (rs LocalRings) RingsAt(t time.Time) bool

RingsAt reports whether the rings ring at t's own local minute, so an occurrence at t waits for no later ring.

type Outcome

type Outcome string

Outcome is what became of one occurrence.

const (
	// Ran: the run finished with exit 0.
	Ran Outcome = "ran"
	// Failed: the run, or what it needed, failed; ExitCode says how.
	Failed Outcome = "failed"
	// Missed: the computer was off, asleep or signed out when it fell due,
	// and the next chance came after the following occurrence.
	Missed Outcome = "missed"
)

type Recurrence

type Recurrence struct {
	Kind Kind `yaml:"kind" json:"kind"`
	// Date is the day of a Once schedule (YYYY-MM-DD).
	Date string `yaml:"date,omitempty" json:"date,omitempty"`
	// Time is the wall-clock time of every occurrence (HH:MM, 24-hour).
	Time string `yaml:"time" json:"time"`
	// Days are the days of a Weekly schedule, lower-case three-letter
	// names (mon … sun), kept sorted Monday first.
	Days []string `yaml:"days,omitempty" json:"days,omitempty"`
	// MonthDay is the day of a Monthly schedule, 1 to 31.
	MonthDay int `yaml:"monthDay,omitempty" json:"monthDay,omitempty"`
	// Zone is the IANA time zone the times are in (Europe/London).
	Zone string `yaml:"zone" json:"zone"`
	// Start is the instant the schedule was made: nothing before it is an
	// occurrence.
	Start time.Time `yaml:"start" json:"start"`
	End   End       `yaml:"end,omitempty" json:"end,omitempty"`
}

Recurrence is when a schedule is due.

func (Recurrence) Between

func (r Recurrence) Between(from, to time.Time, limit int) []time.Time

Between is every occurrence in (from, to], at most limit of them (0: no limit). A calendar asks it for a month; fire asks it for what fell due.

func (Recurrence) Describe

func (r Recurrence) Describe() string

Describe is the repeat in words, for a list and a confirmation.

func (Recurrence) Next

func (r Recurrence) Next(after time.Time) (time.Time, bool)

Next is the first occurrence strictly after after, or false when the calendar has none left. An EndAfter count is not the calendar's but the runs': Remaining applies it. r must be valid.

func (Recurrence) Remaining

func (r Recurrence) Remaining(runs int) int

Remaining is how many runs an EndAfter schedule has left after runs of them, and -1 for any other end.

func (Recurrence) Validate

func (r Recurrence) Validate() error

Validate reports the first thing wrong with r.

type RunSpec

type RunSpec struct {
	// OutDir is the folder each scheduled run's own folder is made in.
	OutDir string `yaml:"outDir" json:"outDir"`
	// Input is a task file read at each fire; Task is the schedule's own
	// task text, kept beside the schedule as task.txt.
	Input string `yaml:"input,omitempty" json:"input,omitempty"`
	Task  bool   `yaml:"task,omitempty" json:"task,omitempty"`

	Files     []string `yaml:"files,omitempty" json:"files,omitempty"`
	Knowledge []string `yaml:"knowledge,omitempty" json:"knowledge,omitempty"`
	// Intake answers (id=value), never a secret question's.
	Intake  []string `yaml:"intake,omitempty" json:"intake,omitempty"`
	Voice   bool     `yaml:"voice,omitempty" json:"voice,omitempty"`
	NoVoice bool     `yaml:"noVoice,omitempty" json:"noVoice,omitempty"`

	Timeout  int     `yaml:"timeout,omitempty" json:"timeout,omitempty"`
	MaxTurns int     `yaml:"maxTurns,omitempty" json:"maxTurns,omitempty"`
	MaxCost  float64 `yaml:"maxCost,omitempty" json:"maxCost,omitempty"`
	Adapter  string  `yaml:"adapter,omitempty" json:"adapter,omitempty"`
	Policy   string  `yaml:"policy,omitempty" json:"policy,omitempty"`
	// Model is the id of the saved model the schedule names, empty for the
	// computer's default: a name, never a credential. Removing a saved model
	// a schedule names is refused until the schedule is moved.
	Model string `yaml:"model,omitempty" json:"model,omitempty"`

	// DeliverTo is the absolute folder each fire copies its deliverables to,
	// as `agentry run --deliver-to` does; empty copies nowhere (a fire still
	// takes deliver.folder from the CLI's config). Destinations are the saved
	// destinations' names each fire sends its result and deliverables to, as
	// `agentry run --destination` does. Names, never a credential: those stay
	// in the keychain, and in the sealed credential of a signed-out schedule.
	DeliverTo    string   `yaml:"deliverTo,omitempty" json:"deliverTo,omitempty"`
	Destinations []string `yaml:"destinations,omitempty" json:"destinations,omitempty"`

	// Hosts are the target hosts the schedule was readied for, when it was
	// made: the answer is in Intake; each keeps where its sign-in is saved
	// and the host key the person accepted. Never a credential.
	Hosts []Host `yaml:"hosts,omitempty" json:"hosts,omitempty"`

	// The consents a person gave, explicitly, when the schedule was made;
	// a fire passes only these.
	AllowUnsigned      bool `yaml:"allowUnsigned,omitempty" json:"allowUnsigned,omitempty"`
	AllowUnscanned     bool `yaml:"allowUnscanned,omitempty" json:"allowUnscanned,omitempty"`
	AllowVulnerableMCP bool `yaml:"allowVulnerableMcp,omitempty" json:"allowVulnerableMcp,omitempty"`
	// UnsafeMode: those consents were given in Agentry Desktop's Unsafe
	// Mode, so the schedule does not run while managed settings on this
	// computer forbid Unsafe Mode. It sets nothing by itself.
	UnsafeMode bool `yaml:"unsafeMode,omitempty" json:"unsafeMode,omitempty"`
}

RunSpec is the run setup's answers a fire passes to `agentry run`.

type Schedule

type Schedule struct {
	ID   string `yaml:"id" json:"id"`
	Name string `yaml:"name" json:"name"`

	// Ref is ns/name of a registry release, pinned to Version and Digest:
	// a fire runs exactly the version consented to when the schedule was
	// made. Local is a QuickAgent directory instead of a ref.
	Ref      string `yaml:"ref,omitempty" json:"ref,omitempty"`
	Version  string `yaml:"version,omitempty" json:"version,omitempty"`
	Digest   string `yaml:"digest,omitempty" json:"digest,omitempty"`
	Local    string `yaml:"local,omitempty" json:"local,omitempty"`
	Registry string `yaml:"registry,omitempty" json:"registry,omitempty"`

	Run  RunSpec    `yaml:"run" json:"run"`
	When Recurrence `yaml:"when" json:"when"`

	// SignedOut: the schedule also runs while its person is signed out
	// (Linux only): its alarm is started by a lingering user manager and
	// reads its keys from the encrypted credential beside it
	// (signedout.go), never from the keychain.
	SignedOut bool `yaml:"signedOut,omitempty" json:"signedOut,omitempty"`

	Paused  bool      `yaml:"paused,omitempty" json:"paused,omitempty"`
	Created time.Time `yaml:"created" json:"created"`
}

Schedule is one calendar entry for a run on this computer: what to run, how, and when. It never holds a credential: the model key stays in the keychain and secrets in the policy's source.

type State

type State struct {
	// Last is the latest occurrence handled (ran, failed or missed).
	Last time.Time `json:"last,omitempty"`
	// Ended is set once no occurrence is left.
	Ended bool `json:"ended,omitempty"`
	// Runs counts the occurrences fire ran (succeeded or failed), for an
	// end after N runs; a missed occurrence and a Run now are not counted.
	Runs int `json:"runs,omitempty"`
}

State is what fires have done to a schedule; only fire writes it, so an edit and a fire never race over one file.

type Store

type Store struct{ Dir string }

Store is the folder of schedules under the runner home. It is the truth about them; the operating system's entries are only alarms.

func StoreIn

func StoreIn(runnerHome string) Store

StoreIn is the store under a runner home.

func (Store) AppendFire

func (s Store) AppendFire(id string, f Fire) error

AppendFire adds one occurrence's record.

func (Store) Claim

func (s Store) Claim(id string, occurrence time.Time) (bool, error)

Claim takes one occurrence for this process: true once, false for every later caller, so two triggers for one occurrence run it once.

func (Store) Create

func (s Store) Create(sc *Schedule, task []byte) error

Create gives sc an id and keeps it, with its task text when task is not nil.

func (Store) CredentialPath

func (s Store) CredentialPath(id string) (string, error)

CredentialPath is where sc's encrypted credential is kept.

func (Store) EnableLinger

func (s Store) EnableLinger(l *Linger, in io.Reader, errOut io.Writer, now time.Time) (bool, error)

EnableLinger turns linger on for the person if it is off, and records that it was this CLI's doing. Linger the person turned on themselves is left as it is, and never recorded as the CLI's. It reports whether it turned linger on now.

func (Store) Fires

func (s Store) Fires(id string, limit int) ([]Fire, error)

Fires reads a schedule's records, newest last; limit keeps only the newest that many (0: all). A line that does not parse is skipped.

func (Store) Get

func (s Store) Get(id string) (Schedule, error)

Get reads one schedule.

func (Store) List

func (s Store) List() (out []Schedule, bad []error, err error)

List reads every schedule, oldest first. A folder that does not hold a readable schedule is skipped and reported in bad.

func (Store) MoveCredential

func (s Store) MoveCredential(from, id string) error

MoveCredential makes the credential at from id's own.

func (Store) PendingCredentialPath

func (s Store) PendingCredentialPath() (string, error)

PendingCredentialPath is a fresh path in the store for a credential sealed before its schedule has an id (add probes it first); MoveCredential gives it to the schedule.

func (Store) Prune

func (s Store) Prune(id string, before time.Time)

Prune removes the claims of occurrences before before: they only stop a duplicate fire of an occurrence that has long been handled.

func (Store) ReleaseLinger

func (s Store) ReleaseLinger(l *Linger, in io.Reader, errOut io.Writer) (bool, error)

ReleaseLinger turns linger off when no schedule runs signed out any more and the CLI was the one that turned it on; otherwise it leaves linger as it is. It reports whether it turned linger off.

func (Store) Remove

func (s Store) Remove(id string) error

Remove deletes a schedule and its record.

func (Store) Save

func (s Store) Save(sc Schedule) error

Save writes sc's definition.

func (Store) SaveState

func (s Store) SaveState(id string, st State) error

SaveState writes what fires have done.

func (Store) SignedOutLeft

func (s Store) SignedOutLeft() (int, error)

SignedOutLeft counts the schedules that still run signed out: made so, and not ended (a paused one counts: it runs signed out again when resumed).

func (Store) State

func (s Store) State(id string) (State, error)

State reads what fires have done; none yet is the zero State.

func (Store) TaskPath

func (s Store) TaskPath(id string) (string, error)

TaskPath is where a schedule's own task text is kept.

type Systemd

type Systemd struct {
	// Dir is the user unit folder (~/.config/systemd/user).
	Dir string
	// Systemctl runs `systemctl --user` with args; replaced in tests.
	Systemctl func(args ...string) error
	// SystemdRun runs `systemd-run --user` with args and returns its
	// output; replaced in tests.
	SystemdRun func(args ...string) ([]byte, error)
	// Running reports whether a unit is starting, running or stopping;
	// nil is never. Replaced in tests.
	Running func(unit string) bool
}

Systemd is the Linux alarm: a systemd user timer and service per schedule, in the person's own manager (no root, and the session's bus so the keychain is reachable while they are signed in). Cron is not used: a cron job has no session bus.

func NewSystemd

func NewSystemd() (*Systemd, error)

NewSystemd is the alarm for the person running this process.

func (*Systemd) Install

func (s *Systemd) Install(sc Schedule, e Entry) error

Install implements Alarm.

func (*Systemd) Installed

func (s *Systemd) Installed() ([]string, error)

Installed implements Alarm.

func (*Systemd) Name

func (*Systemd) Name() string

Name implements Alarm.

func (*Systemd) Probe

func (s *Systemd) Probe(e Entry) (string, error)

Probe implements Alarm: a transient unit in the person's own manager, waited for, its output piped back.

func (*Systemd) Remove

func (s *Systemd) Remove(id string) error

Remove implements Alarm. The timer goes at once. The service's file stays while the service runs: a fire that ends its own schedule removes its alarm from inside that service, and a reload that finds a running unit's file gone reloads it with the manager's defaults, among them a start timeout (45 s on Fedora) that stops a run already longer than that. Such a file, inert without its timer, is swept by the next Install or Remove once its service has stopped.

type TaskScheduler

type TaskScheduler struct {
	// UserSID is the person's security identifier, the task's principal.
	UserSID string
	// Conhost is the absolute path of conhost.exe.
	Conhost string
	// Loc is this computer's zone, the one the triggers keep.
	Loc *time.Location
	// Schtasks runs schtasks.exe with args and returns its output;
	// replaced in tests.
	Schtasks func(args ...string) ([]byte, error)
	// Now is the clock the triggers are compiled from; replaced in tests.
	Now func() time.Time
	// Wait is how long Probe waits for its report.
	Wait time.Duration
}

TaskScheduler is the Windows alarm: a task per schedule that runs as the person, only while they are logged on (an interactive token, so Credential Manager and Docker Desktop are theirs), and never wakes the computer. Its calendar keeps local time, so its triggers are LocalRingsFor's superset. A logon trigger and StartWhenAvailable are the catch-up for an occurrence missed while the computer was off, asleep or signed out; fire decides whether it still runs.

A task cannot set its program's environment, so the entry's Env travels as `--env KEY=VALUE` arguments, which fire and probe apply first; and it runs through `conhost --headless`, so no console window opens on the person's screen at every ring.

func NewTaskScheduler

func NewTaskScheduler() (*TaskScheduler, error)

NewTaskScheduler is the alarm for the person running this process.

func (*TaskScheduler) Install

func (ts *TaskScheduler) Install(sc Schedule, e Entry) error

Install implements Alarm: the task in \Agentry\, or in the root where the folder cannot be made, and none left in the other place.

func (*TaskScheduler) Installed

func (ts *TaskScheduler) Installed() ([]string, error)

Installed implements Alarm.

func (*TaskScheduler) Name

func (*TaskScheduler) Name() string

Name implements Alarm.

func (*TaskScheduler) Probe

func (ts *TaskScheduler) Probe(e Entry) (string, error)

Probe implements Alarm: a task with no trigger, started once, in the person's logged-on session, removed afterwards.

func (*TaskScheduler) Remove

func (ts *TaskScheduler) Remove(id string) error

Remove implements Alarm.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL