class Rosegold::Intervention

Overview

Standing, opt-in permission for an operator to take over a running script. A takeover gates scripted input at once through ManualControl, then parks the registered script fiber at its next Bot#wait_tick(s). Only that fiber ever blocks; the ticker, event handlers and other fibers keep running.

Defined in:

rosegold/control/intervention.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(client : Rosegold::Client) #

[View source]

Instance Method Detail

def active? : Bool #

[View source]
def can_take_over? : Bool #

Whether a takeover could start now: permitted, a script registered, no takeover in progress, no manual grant or release outstanding, and no cancellation still waiting for a live owner's checkpoint.


[View source]
def cancel(grant_id : UInt64, reason : ManualControl::Reason) : Bool #

Forced loss or disable of the controller. Rejects a stale grant, revokes with reason and wakes a parked owner. When inventory work is unresolved, the owner's checkpoint raises ManualControl::Cancelled rather than continuing blindly; otherwise it resumes as after a normal return. Either way the cancellation is kept in #last_cancellation.


[View source]
def checkpoint : Nil #

Called by Bot#wait_tick(s); parks only the fiber the takeover was requested for.


[View source]
def client : Client #

[View source]
def finish_restart : Nil #

Called by Bot.run after an unwound restart, before the next connection.


[View source]
def grant_ended(grant_id : UInt64, reason : ManualControl::Reason, unresolved : Bool) : Nil #

Called by ManualControl whenever a grant ends, whatever ended it. Resolves the matching takeover exactly once; a forced end with unresolved inventory makes the owner's next checkpoint raise.


[View source]
def grant_id : UInt64 | Nil #

[View source]
def last_cancellation : ManualControl::Cancelled | Nil #

The most recent forced cancellation, kept for the companion to report.


[View source]
def parked? : Bool #

[View source]
def pending? : Bool #

[View source]
def permitted=(value : Bool) #

Turns the standing permission on or off. Turning it off ends a takeover.


[View source]
def permitted? : Bool #

[View source]
def register_owner(fiber : Fiber = Fiber.current, restartable : Bool = false) : Nil #

Registers the fiber that runs the script. restartable is true only for Bot.run, which can rebuild the session; a custom runner can resume only.


[View source]
def release_owner : Nil #

[View source]
def request_takeover : UInt64 | Nil #

Takes over: gates scripted input and cancels pending intentions now. Returns the manual grant id, or nil when not permitted, no script is registered, or control is already held. The takeover binds the owner registered when it was requested; if starting the grant revokes it, changes the owner or permission, or starts another takeover, the grant is returned.


[View source]
def reset : Nil #

Backstop for a session change. ManualControl#reset is the supported entrypoint and has already delivered any pending cancellation to the old owner, which survives this call; a later owner never inherits it.


[View source]
def restart(grant_id : UInt64 | Nil = nil) : Bool #

Unwinds the parked script and restarts its Bot.run block from the top on a fresh connection. Rejected until the script is parked, or when the runner the takeover was requested for cannot restart.


[View source]
def restart_requested? : Bool #

Whether a restart was requested and Bot.run has not yet handled it. The unwind raises RestartRequested once, at the parked checkpoint. A user rescue can swallow that one raise, so Bot.run also checks this flag after the block returns. Later checkpoints do not raise again, which keeps an ensure that waits ticks running to completion. Restart is cooperative: a retry loop that swallows the raise keeps running, and no further takeover, resume or restart is possible until the block exits.


[View source]
def restartable? : Bool #

[View source]
def resume(grant_id : UInt64 | Nil = nil) : Bool #

Ends the takeover and continues the script at the point where it parked.


[View source]
def state : State #

[View source]