magus v0.4.2 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 daemon); 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. opts: {backoff_ms:float (default 500), max_backoff_ms:float (default 30000)}.

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 (4f8cc295)
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. See targets.

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. See targets.

Op

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

Module

A magus stdlib namespace a magusfile imports for host capabilities: filesystem, exec, vcs, and more. See the module reference.

Buzz

The language magusfiles are written in (the .buzz engine). See engines.

Daemon

The background magus host that owns shared state such as services and the warm knowledge graph. See daemon.

CI

An ordinary magusfile-defined target you compose yourself with magus\needs - magus does not hardcode its stages. Magus.RunCI treats it specially only in that it strips the rw charm, it is the anchor magus affected ci keys off, and a selected scope with no project declaring it is a load error rather than a silent no-op. See targets.

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). See daemon.

Conventions

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