KScript docs
EN

Queues and jobs: KScript.Queue

Testing jobs

kscript test runs jobs on the sync connection, so a dispatched job runs straight away, unless queue.env.test in kscript.json says otherwise. To check what a piece of code dispatches without running it, call @fake_queue() first:

<import package="KScript.Queue" />
<import path="jobs/send-welcome.kscript" />

<let name="queue" value="@fake_queue()" />
<do>SendWelcome(user_id: 7, email: 'joan@example.com')->dispatch()</do>

<echo>{$queue->count_of(SendWelcome)} welcome email queued for user {$queue->pushed(SendWelcome)[0].user_id}</echo>
<do>$queue->run_all()</do>
import KScript.Queue
import "jobs/send-welcome.kscript"

$queue = @fake_queue()
SendWelcome(user_id: 7, email: 'joan@example.com')->dispatch()

echo "{$queue->count_of(SendWelcome)} welcome email queued for user {$queue->pushed(SendWelcome)[0].user_id}"
$queue->run_all()

The fake queue's ->pushed(Job) lists the dispatched jobs, and ->dispatches() lists what each dispatch asked for (queue, connection, delay). ->count() counts them, and ->count_of(Job) counts those of one job. ->run_all() runs them here, and ->clear() forgets them.