Repository navigation
feat: a lease window holds work to set hours - #290
Merged
Merged
Conversation
A user who wants work on the card only while power is cheap writes window = "23:00-07:00" on an engine entry. The value parses from "HH:MM-HH:MM", may cross midnight, and keeps that spelling in TOML, JSON and YAML through the text codec; the zero value names no window, so an entry that says nothing is held to no hours. The type is proto's rather than config's: berthd decides grants by the window, and config reaches the broker only through claims, so a type in config would close an import cycle. The engine entry, the socket message and the lease all read the same value.
The two-digit check is its own rule, and every bad string the table had so far was already caught by the length check. "1O:00" is five characters with a colon in the right place, so it is the one that says whether the code looks at the digits at all.
A lease carries its window from the request that asked for the card. Outside its hours a waiter does not fit and drains nothing: it reads "outside its window 23:00-07:00; opens in 3h12m" and keeps its place in the queue. The tick after hours close drains the holder with "its window 23:00-07:00 closed" and evicts a parked one, once each, and a lease with no window is untouched. A window close is a drain, so the boundary a drain names comes first and a request in flight is never cut off. The hours ride the way min_turn does: the entry's window or berth run --window, through runner.Options and the socket into the lease, and back out on a re-attach so a daemon restart does not lose them. A window goes with neither --pinned nor --priority hold, since nothing drains either, and a window the socket cannot read is refused there rather than read as none. Drain and evict come out of schedule and evictParked, so a closed window asks for the card back the same way a waiter does.
An engine outside its hours stays down: started, it would only sit in the queue for a lease berthd cannot grant yet. The clock it is measured by, freeSince, is the card's and not the engine's, so it keeps running while the window is shut and the engine starts on the tick its window opens with. Dropping the key here would reset the idle wait of every other engine on that card.
leasing.md gets the section: a batch lease yields to any request, a background engine waits for a free card, and a window holds either to set hours, with the entry and the berth run line. A close is a drain at the boundary, so work that is not a server saves checkpoints, and a timer can start it at the open. gateway.md gets one sentence and one TOML line in its background section, and the CHANGELOG one entry.
…r it A batch run waiting for its night window sat at the head of the queue, so a later batch job with no window waited all day on a free card and read the windowed run's reason as its own. A waiter outside its window now steps out of line until the window opens, and reads its own reason. berthd's default wait (120 s) also refused a run started at noon for a night window. A windowed request that names no --wait now waits for its window with no deadline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A user asked for jobs that run only when they are not working, or only when electricity is cheapest. Berth already runs batch work in the gaps (
--priority batch,background = true), but it had no idea of time of day. This adds one.What changes for users
window = "23:00-07:00"on an[[engine]]entry, orberth run --window 23:00-07:00, holds the lease to those hours on the node's clock. A window may cross midnight.--waitsets one, and it does not block other waiters. Its reason readsoutside its window 23:00-07:00; opens in 3h12m.--windowis refused with--pinnedand with--priority hold, because a window close is a drain and those leases are never drained.How it works
The window is a lease field in the broker, next to
min_turn, soberth statusshows the wait and a re-attach after a berthd restart keeps it. The type lives ininternal/proto, because the broker must not importconfig. Inschedule, waiters outside their window step out of the queue before it runs.Tickdrains or evicts holders whose window closed, once per lease.Proof
go test ./..., the Windows build and vet, and golangci-lint (0 issues) all pass.sleepjobs that never touch the card. A run with window 08:03-08:05 readopens in 2m, waited past the daemon's--wait 10s, got the card at 08:03:01 and drained at 08:05:01 withits window 08:03-08:05 closed. A later batch run with no window got the card at once while the first one waited.