magus v0.4.3 is out. See what's new
¶ View generated markdown
2 min read

os

The machine and this process: platform triple, CPU count, hostname, the running magus binary, and the two members that shadow Buzz's own (exit, sleep). Running OTHER processes lives in the proc module.

Naming convention: import the module under its bare name (import "os"), reach members with a backslash, and call methods in camelCase: os\someMethod.

Methods

withEnv

Add env vars to subprocesses proc\exec / proc\shell start inside callback. Never touches the process's own environment - a lookup like os\env inside callback does not see them.

Signature: os\withEnv(env, callback) - source

Parameter Type Optional Description
env map[string]string
callback Callback

platform

Return the Docker/OCI platform triple: (os, arch, variant).

Signature: os\platform() -> string, string, string - source

Returns: string, string, string

exit

Abort the current run with the given exit code - typically after logging an error. Does NOT call os.Exit (that would kill a shared server); it raises, ending the target, and the code becomes magus's process exit status.

Signature: os\exit(code) - source

Parameter Type Optional Description
code int

sleep

Pause for the given number of milliseconds (fractional allowed), matching Buzz's os\sleep. Cancellable: if the run is interrupted it returns early with the cancellation error rather than blocking.

Signature: os\sleep(ms) - source

Parameter Type Optional Description
ms float64

numCpu

Return the number of logical CPUs available, for sizing a command's own internal parallelism (see os\with_slots).

Signature: os\numCpu() -> int - source

Returns: int

hostname

Return the host machine's name.

Signature: os\hostname() -> string - source

Returns: string

executable

Return the absolute path of the running magus binary. Pair it with fs\stat inside a long-lived watch loop to detect that the binary was rebuilt or upgraded underneath the process, which means any output it goes on to generate would be stale.

Signature: os\executable() -> string - source

Returns: string

retry

Call fn up to max times, retrying on error with exponential backoff; returns fn's value on success. An error a host call inside fn raised keeps its type, and one typed non-retryable stops at once; a value fn throws itself, a string included, is retried. opts: {backoff_ms:float (default 500), max_backoff_ms:float (default 30000)}; a wrongly typed or negative option raises.

Signature: os\retry(max, fn, [opts]) -> any - source

Parameter Type Optional Description
max int
fn Callback
opts map[string]any yes

Returns: any

generatedreference/buzz/osmodulestdlibmagusfile
Last updated (29d8b3de)
Earlier changes on this page (7)

Full history ↗ · Blame source ↗

Glossary

Magusfile

The magusfile.buzz that declares a project's targets (as export funs) and binds its spells. Magusfile in full.

Target

A named operation (build, test, ...) you invoke with magus run <target>; it may compose a spell's tool-native operations and depend on other targets. Target in full.

Op

A single tool-native command a target composes (long form: operation); the middle of the work hierarchy (Spell to Op to Target). Op in full.

Module

A magus stdlib namespace a magusfile imports for host capabilities: filesystem, exec, vcs, and more. Module in full.

Buzz

The language magusfiles are written in (the .buzz engine). Buzz in full.

CI

An ordinary target you compose yourself with ctx.needs; magus does not hardcode its stages. It is the anchor magus affected ci keys off, and ci strips the rw charm. CI in full.

Slot

One unit of the pool's capacity. A target acquires the slots it needs to run (most take one) and releases them when it finishes; the pool tracks capacity (total slots), running (acquired), and queued (blocked). Slot in full.

Run

One target executing under one magus invocation, such as magus run test web or magus affected ci. A run keeps its captured output behind an output reference. Every magus run is a run whether or not any job asked for it; see Job for how the two relate. Run in full.

Conventions

This page uses none of the site's convention markers. The full set is on the conventions page.