omp packages

pi-web-jobs0.6.6

A PI WEB tab that shows the selected workspace's jobctl jobs, their schedules, running runs, logs, and run/stop actions.

GitHub Actions Published 1 day ago MIT ~264 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

Jobs

npm version

A PI WEB tab that shows the selected workspace's jobctl jobs: which schedules are active, what ran last, and what is running now. Activate and Deactivate control a job's scheduler entry, Run starts a job, Stop ends a running job, Log shows the tail of its output, and Delete removes the job for good.

The Jobs tab in PI WEB with the log of a nightly job open

The real tab in PI WEB on a nightly workspace: the active schedule and its last result, two on-demand jobs, and the log of nightly-gate with the colours the test runner wrote. The host supplies the theme tokens and the button styles.

Why it is good

  • The schedule and its result sit together. jobctl keeps the schedule in the workspace's jobs.toml and the runs in its state directory. The tab shows whether each scheduler entry is active, when it next runs, and what happened last, in one row instead of three commands.
  • The log keeps its colours. jobctl writes a job's output unchanged, so a program that thinks it is on a terminal leaves SGR escape sequences in output.log. The panel reads them into styled runs, so a test runner's green ticks and red failures look the way they were written instead of [32m…[39m.
  • Actions go through jobctl. Run and Stop, Activate and Deactivate, and Delete all call the same binary a scheduled run does, so a manual run takes the same locks, timeout, receipt and log as a nightly one.
  • A running job stays in its row. The newest receipt says whether a job is running, and its row then shows how long it has been running with a Stop button where Run would be, so nothing is drawn twice. The Jobs label carries a pulsing dot while any job runs.
  • A local config file is read beside the shared one. jobs.local.toml may restate a job that jobs.toml defines, and the header lists every file it read, so a job is never shown without saying where it came from.
  • Delete removes the whole job. The definition leaves the config file that holds it, the scheduler unit is uninstalled, and the run history is removed. The browser's own confirm dialog asks once, because the definition is a file in the repository.
  • Nothing else to run. It adds a tab to PI WEB, with no database and no extra service. jobctl stays the only thing it talks to.

How it works

jobs.toml, jobs.local.toml ──► jobctl list --json ───┐
                                                     ├──► overview ──► Jobs tab (refresh every 2 s)
stateDir/runs/<job>/<run>/meta.json ─────────────────┘

Run, Stop, Activate, Deactivate, Delete ──► jobctl <verb> NAME ──► receipt and log on disk
Log ─────────────────────────────────────► tail of runs/<job>/<latest run>/output.log

The plugin is one browser entry plus one server module. The browser entry asks the server peer for an overview and for a log; the server reads jobctl and the state directory. Neither side keeps state of its own, so the tab always reports what is on disk.

Requirements

  • PI WEB with browser API v5 and server API v5, including the stylesheet-integration v1 capability. It was checked on PI WEB 1.202611.6. An older host skips the tab instead of rendering it unstyled.

  • jobctl on the session daemon's PATH, or named through binary below. It must provide:

    • run, stop, install, uninstall and logs, plus list --json
    • list --json naming each job's config file in config, and a --config flag that may be repeated, so the panel can read jobs.toml and jobs.local.toml together

    Those two arrived in jobctl commit 088b38d, and no release tag exists yet. An older build reads one config file: the overview still lists jobs, but Delete cannot tell which file defines a job and refuses, and a run of a job defined only in jobs.toml fails with unknown job.

  • A jobs.toml in the selected workspace, and optionally a jobs.local.toml beside it.

  • A session-daemon restart after installation, because the plugin has a server entry. A browser reload alone is not enough.

  • A session-daemon restart after every update as well, including a documentation-only one. The host serves a plugin's browser files from the revision the daemon has activated, and a package whose files changed advertises a revision the running daemon cannot serve: a page reload then loses the tab until the daemon restarts. The open tab keeps working, because its code is already loaded.

Install

The package is pi-web-jobs on npm. It ships compiled JavaScript, so installing or updating it never needs a build.

pi install npm:pi-web-jobs
systemctl --user restart pi-web-sessiond

Or open Settings → Pi packages in PI WEB, enter npm:pi-web-jobs, and install it there. Restarting the session daemon interrupts active sessions and terminals, so finish important work first.

To follow main between releases, install the git source instead:

pi install git:github.com/ivolejon/pi-web-jobs
systemctl --user restart pi-web-sessiond

Local development

Clone the repository, build it, and link it as a local PI WEB plugin:

git clone https://github.com/ivolejon/pi-web-jobs.git
cd pi-web-jobs
npm install
npm run build
ln -sfn "$(pwd)" ~/.pi-web/plugins/jobs

Then reload the browser, restart the session daemon once, and enable Jobs under Settings → PI WEB plugins if it is not enabled by default. The linked clone wins over an installed package. On a machine where PI_WEB_DATA_DIR is set, link into $PI_WEB_DATA_DIR/plugins instead.

npm run check type-checks without writing, and npm test builds and runs the suite.

Update

pi update npm:pi-web-jobs
systemctl --user restart pi-web-sessiond

Or update it under Settings → Pi packages. The daemon restart is required even when only a browser file changed: the host serves the revision the daemon activated, and the tab is withheld until the two agree. Reload the browser afterwards. A symlinked development clone is updated with git pull, npm run build, and the same restart.

Remove

pi remove npm:pi-web-jobs
systemctl --user restart pi-web-sessiond

Reload the browser page. Settings → PI WEB plugins can also disable the tab without removing the package. If you linked a development clone, delete that symlink.

Settings

The plugin reads machine-global settings. In the PI WEB configuration ($PI_WEB_CONFIG, or ~/.config/pi-web/config.json):

{
  "plugins": {
    "jobs": {
      "enabled": true,
      "settings": {
        "binary": "/usr/local/bin/jobctl",
        "stateDir": "/root/.local/state/jobctl",
        "config": "jobs.toml"
      }
    }
  }
}
Setting Meaning Default
binary The jobctl binary or its name $JOBCTL_BIN, then jobctl
stateDir The state directory jobctl uses $JOBCTL_STATE_DIR, $XDG_STATE_HOME/jobctl, ~/.local/state/jobctl
config The config file, relative to each workspace jobs.toml

Restart the session daemon after a settings change.

What it does

Section Source
Config files <workspace>/jobs.toml, then <workspace>/jobs.local.toml when it exists
Scheduled jobs jobctl list --json over every config file
Schedule state on Linux The active state of jobctl-<name>.timer in the systemd user manager
Schedule state on macOS Whether com.jobctl.<name> is loaded in the user's launchd domain
Running jobs A job whose newest receipt still says running keeps its table row, where its elapsed time and Stop replace Run
Last run The newest receipt for the job: its finish time, then its status and duration. The finish time is the receipt's endedAt, or its startedAt plus durationSeconds for a receipt written before that field existed
Log The last 64 KiB of the newest run's output.log, with ANSI colour sequences drawn as colours
Tab badge A pulsing dot while any job's latest receipt is running; it polls every 1.5 s while running and every 5 s while idle, and stops when the tab strip unmounts
Delete jobctl list --json names the file; the table is removed, jobctl uninstall drops the unit, and runs/<job>/ is removed

The tab refreshes every two seconds while it is open and when the workspace's files change. On-demand jobs have no schedule to order them by, so the one that finished most recently is listed first and a job that has never run comes last. The tab-strip badge runs its own small timer, because the host redraws a badge only when it redraws the strip and a job finishes without that. The badge is a hint, never a claim: an unreadable overview hides it.

The host draws every badge as a teal pill, which suits a count rather than a status light. jobs-badge.css removes that pill for the Jobs badge only, through .tab-badge:has(jobs-activity), so the marker is a plain dot beside the label. If a later host renames the class the rule stops applying and the pill returns; nothing else depends on it.

Status, card and row colours use the PI WEB theme tokens, not hard-coded colours: --pi-surface for the job background (a little lighter than the page's --pi-bg), --pi-success and --pi-danger for the check and cross, --pi-accent for a running spinner and --pi-muted for a never-run dash. The tab follows the selected light, dark or paper theme.

The open log is remembered per workspace in session storage. After a page reload it reopens and scrolls to the bottom. A refresh keeps your scroll position unless you were already at the bottom.

The log keeps the program's colours. jobctl writes the job's output unchanged, so a program that thinks it is on a terminal leaves SGR escape sequences in output.log; the panel reads them into styled runs instead of showing them literally. The colours come from the PI WEB theme tokens, so they follow the selected theme: red is --pi-danger, green --pi-success, yellow --pi-warning, blue --pi-thinking, cyan --pi-tool, magenta --pi-purple and grey --pi-dim. Bold, dim, italic, underline and reverse video are drawn too, and a 256-colour or 24-bit sequence uses the colour it names. Cursor movement, window titles and other non-colour sequences carry no meaning here and are dropped, and a progress bar's carriage returns become line breaks.

Activate runs jobctl install NAME with every config file and the configured state directory. Deactivate runs jobctl uninstall NAME. Both operations use jobctl's ownership checks and show its diagnostic if the scheduler refuses the change. A job disabled in jobs.toml cannot be activated, but an existing scheduler entry can still be deactivated.

Run runs jobctl run NAME --trigger manual. A busy lock, an invalid config or an unknown job is shown in the tab; jobctl's own run receipt and log are the record.

Stop runs jobctl stop NAME. jobctl sends SIGTERM to the runner, which forwards it to the job's process group, waits kill_grace, records the run as interrupted and exits 143. The tab returns as soon as the stop is requested and the next refresh shows the final status. A job that is not running, or whose recorded runner is gone, is reported instead of being signaled.

Disabled jobs can still be run manually, as in jobctl.

Delete removes a job for good: its definition from the config file that holds it, its scheduler unit, and its run history. The browser's own confirm dialog asks once before anything happens, because the definition is a file in the repository. A definition that is an inline jobs.<name> = { … } rather than a [jobs.<name>] table is refused, since rewriting it correctly needs a TOML writer this plugin does not have. A running job must be stopped first.

Limits

  • Schedule state is Unknown if the plugin cannot query the systemd user manager or the launchd user domain. The plugin does not infer activation from the schedule text or from jobctl's next-run estimate.
  • jobctl scheduler names and state are machine-wide and keyed by job name. Use unique names across workspaces, because an active scheduler entry with the same name is the entry that Deactivate removes.
  • The receipt is the source of "running". A runner killed with SIGKILL can leave a stale running receipt; Stop refuses when the recorded runner is gone or its pid was reused (it compares the process start time).
  • Stop needs a jobctl version with the stop command and a run that wrote its process record. Runs started by an older build cannot be stopped this way.
  • Delete edits the config file that holds the job. When that is the tracked jobs.toml, the change appears as a diff in git; when it is jobs.local.toml, nothing else changes.
  • Delete removes stateDir/runs/<job>/, so the job's log and receipts are gone. Lock files are left alone.

Files

File Role
package.json the piWeb.plugins entry that PI WEB discovers
src/browser/pi-web-plugin.ts contributions: the Jobs workspace panel
src/browser/jobs-panel.ts the panel element: overview, tables, actions, log view
src/browser/view.ts pure helpers for grouping, formatting, response validation and ANSI parsing
src/browser/jobs-activity.ts the tab badge that pulses while a job runs
src/browser/jobs-badge.css drops the host's badge pill for the Jobs badge
src/server/plugin.ts the peer that reads jobctl and the state directory
tsconfig.json, tsconfig.browser.json, tsconfig.server.json strict builds for the shared, browser and server code
browser/, server/ generated by tsc and committed: everything the host serves
docs/images/ the screenshots used by this README
test/ the node:test suite and the panel preview
.github/workflows/test.yml the suite on every push to main and every pull request
.github/workflows/publish.yml tests and publishes a GitHub Release to npm, with provenance

The browser entry is browser/pi-web-plugin.js; the server entry is server/plugin.js. The package is limited to those two directories, the README and the license.

Publishing

Publishing runs in GitHub Actions: .github/workflows/publish.yml tests, checks that the committed build matches src/, packs one tarball, uploads it as the pi-web-jobs Actions artifact, and publishes that exact file on a published GitHub Release, with provenance. The workflow refuses a release whose tag is not v<package.json version> and a version that is already on npm.

The package is published on npm as pi-web-jobs, unscoped and public, and the community directory finds it through the pi-web.dev-plugin keyword. Treat any npm publish on a workstation as a bootstrap or an emergency, not the normal release path.

Release a version

npm version patch        # or minor / major; commits the bump and creates the vX.Y.Z tag
git push --follow-tags
gh release create "v$(node -p "require('./package.json').version")" --generate-notes

A manual Run workflow on the Publish workflow skips the tag check, for a retry.

Trusted publishing

npm trusted publishing supplies the credential: the workflow asks for id-token: write and publishes through OIDC, so no long-lived token is stored. If the repository secret NPM_TOKEN exists the workflow uses it instead, which keeps an older setup working. Once the OIDC publish succeeds, remove the secret and restrict token access under Settings → Publishing access.

After the run, check npm view pi-web-jobs version and the provenance badge on npm. Installations update with:

pi update npm:pi-web-jobs

Every update, browser-only or not, needs a session-daemon restart before the tab loads again.

Tests

npm test compiles src/ to browser/ and server/ and then runs the suite, so a test never passes against a stale build. npm run check type-checks both runtimes without writing.

npm install
npm test

The tests use node:test and fake jobctl and scheduler binaries. They cover schedule state and activation, the server's overview, run, stop and log requests, the missing binary and old-version paths, response validation, and the view helpers, including the ANSI parser. No third-party runtime dependency is needed, for the tests or for the plugin.

test/panel.html is a preview with sample data, including a coloured log. It mirrors the host's button and badge rules, so a styling bug shows up there too. Serve the repository and open it in a browser:

python3 -m http.server 8765
# http://127.0.0.1:8765/test/panel.html

The compiled output is committed because the host serves those files by path. Run npm run build after editing src/ and commit browser/ and server/ with the change. prepack rebuilds them, so npm pack and npm publish always ship what src/ produced. GitHub Actions fails a release when the committed build no longer matches src/.

Verify a change

Build and restart first (npm run build, then systemctl --user restart pi-web-sessiond): the host serves browser/ and server/, not src/.

  1. Reload the browser and open the Jobs tab on a workspace with a jobs.toml. Every job appears once, and the header lists the config files that were read.
  2. Run a job that colours its output, open Log, and confirm the colours are drawn and no [32m text is left. Scroll up and down: the position survives the two-second refresh unless you were at the bottom.
  3. Activate and then deactivate a schedule: the state and next run change, and systemctl --user list-timers agrees.
  4. Open the panel preview (test/panel.html) and check the narrow layout by narrowing the window; the tables become stacked rows and the log stays readable.

License

MIT. See LICENSE.