Class: Textus::Write::Enqueue
- Inherits:
-
Object
- Object
- Textus::Write::Enqueue
- Extended by:
- Contract::DSL
- Defined in:
- lib/textus/write/enqueue.rb
Overview
Push a job of a REGISTERED type onto the convergence queue, to be run by drain/serve. The closed allow-list (Jobs::Handlers.registry) is the safety boundary: an unregistered type is refused, so the general runner can never execute arbitrary code. Authority is checked here (the caller must hold the type’s required_role, if any) and frozen onto the job’s ‘enqueued_by` — the worker runs it as exactly this role, no escalation via the queue.
Instance Method Summary collapse
- #call(type, args = {}) ⇒ Object
-
#initialize(container:, call:) ⇒ Enqueue
constructor
A new instance of Enqueue.
Methods included from Contract::DSL
arg, around, cli, cli_stdin, contract, contract?, summary, surfaces, verb, view
Constructor Details
#initialize(container:, call:) ⇒ Enqueue
Returns a new instance of Enqueue.
19 20 21 22 |
# File 'lib/textus/write/enqueue.rb', line 19 def initialize(container:, call:) @container = container @call = call end |
Instance Method Details
#call(type, args = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/textus/write/enqueue.rb', line 24 def call(type, args = {}) entry = Textus::Jobs::Handlers.registry.lookup(type) # raises UsageError for unregistered types (entry) job = Textus::Domain::Jobs::Job.new( type: type, args: args, enqueued_by: @call.role, max_attempts: entry.max_attempts, ) Textus::Ports::Queue.new(root: @container.root).enqueue(job) { "protocol" => Textus::PROTOCOL, "ok" => true, "id" => job.id } end |