Decide whether a queued request can afford to wait
The bucket has four tokens and needs eight. At two tokens per tick the charge fits the two-tick deadline.
Run the native CLI
Extract the workflow collection for your platform. Run .\bin\petrel.exe --help in PowerShell or ./bin/petrel --help on Linux and macOS. Running the command with no arguments prints the worked example.
Build from source
With Blyx 0.2.1, Rust and a host linker installed, run these commands to edit and rebuild the example.
git clone --depth 1 --branch v0.1.0 https://github.com/Rahulchaube1/blyx-petrel.git cd blyx-petrel blyxc native-run project.blyx -- 2 10 2 1 8 2
Why this framework exists
Charging a delayed request immediately can remove capacity from unrelated work. Return the wait separately from the updated balance. IETF RFC 2697, token buckets
Install Petrel in your editor
Extension RahulChaube.blyx-petrel · 0.1.0
The extension includes a runnable Blyx example, function completions and the framework source. For the modular project, extract the starter, open its folder and run blyxc native-run main.blyx with the native toolchain installed.
Create an empty .blyx file, type blyx-petrel-demo and accept the completion. Choose Blyx: Run File to run the example.
For an offline installation, choose Extensions: Install from VSIX for Blyx Language first, then for Petrel.
Download the companion Blyx Language VSIXLibraries in this framework
Install with Conda
Create an environment containing Petrel 0.1.0, its Blyx source and a runnable example. Run the second command with Blyx 0.2.1, Rust and a host linker installed.
conda create -y --prefix ./blyx-env --override-channels -c https://rahulchaube1.github.io/blyx-packages blyx-petrel=0.1.0=0 blyxc native-run ./blyx-env/share/blyx/petrel/main.blyx
To use this package in your application, copy share/blyx/petrel/vendor/petrel from the environment into your project's vendor directory.
Import into a Blyx project
Install Blyx 0.2.1, Rust 1.85 or newer and a host linker. From the directory containing your entry file, clone this tagged release.
git clone --depth 1 --branch v0.1.0 https://github.com/Rahulchaube1/blyx-petrel.git vendor/petrel
You can also download Petrel as a ZIP. Extract its contents into vendor/petrel.
Save this as main.blyx beside vendor and run blyxc native-run main.blyx.
use vendor::petrel::petrel;
fn main() {
let tokens = 2.0;
let capacity = 10.0;
let rate = 2.0;
let elapsed = 1.0;
let cost = 8.0;
let deadline = 2.0;
let result = petrel_admit(tokens, capacity, rate, elapsed, cost, deadline);
if len(result) == 0 { println!("invalid"); return; }
let mut i = 0;
while i < len(result) {
println!(at(result, i));
i += 1;
}
}Expected output
0 4 1 2
API and input requirements
Returns [charge now, balance after immediate decision, feasible by deadline, wait]. Deferred work consumes no tokens until resubmitted. Invalid arguments and nonfinite results return an empty vector.
| API | Use |
|---|---|
petrel_admit(tokens, capacity, rate, elapsed, cost, deadline) | Returns [charge now, balance after immediate decision, feasible by deadline, wait]. Deferred work consumes no tokens until resubmitted. |
Develop and contribute
Open the tagged source to read the implementation and examples. Include the smallest reproducible Blyx program, compiler version and expected result when reporting an issue.
