KScript docs
EN

job fields and methods

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

From KScript.Queue

These need <import package="KScript.Queue" />import KScript.Queue. See KScript.Queue.

#job->dispatch(delay?: duration, at?: date, queue?: string(min: 1), connection?: string(min: 1), after_commit?: bool) → map KScript.Queue

Queues the job and returns what was queued: { id, job, queue, connection, available_at }. delay (10m) or at (a date) make it wait; null when a unique job is already queued. Inside a transaction the job is queued when it commits, and dropped if it rolls back; not after_commit queues it at once.
ParameterTakes
delay optionalduration
at optionaldate
queue optionalstring(min: 1)
connection optionalstring(min: 1)
after_commit optionala flag: after_commit or not after_commit

Arguments can be named: ->dispatch(…, at: …, queue: …).

Example
<job name="Hello" fields="who: string">
  <fn name="handle"><echo>Hello { $who }</echo></fn>
</job>
<do>@fake_queue()</do>
<let name="queued" value="Hello(who: 'Joan')->dispatch(delay: 10m, queue: 'high')" />
<echo>{ $queued.queue }</echo>
job Hello {
  who: string
  fn handle() {
    echo "Hello { .who }"
  }
}
@fake_queue()
$queued = Hello(who: 'Joan')->dispatch(delay: 10m, queue: 'high')
echo $queued.queue

#job->run() → any KScript.Queue

Runs the job's handle now, here, without a queue. Errors reach the caller.
Example
<job name="Hello" fields="who: string">
  <fn name="handle"><echo>Hello { $who }</echo></fn>
</job>
<do>Hello(who: 'Joan')->run()</do>
job Hello {
  who: string
  fn handle() {
    echo "Hello { .who }"
  }
}
Hello(who: 'Joan')->run()

Methods from any