batch 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).
Fields Field Type Description .created_atdate When it was dispatched. .failed_countnumber How many of its jobs failed, after their tries. .failed_idslist The ids of the jobs that failed, for @queue()->retry(id). .finished_atdate When its last job finished, or null. .idstring The batch's id, for @queue()->batch(id). Null until it is dispatched. .is_finishedbool True once every job has finished. .pendingnumber How many of its jobs haven't finished yet. .processednumber How many of its jobs have finished, whether they succeeded or failed. .progressnumber How much of the batch has finished, from 0 to 100. .totalnumber How many jobs the batch has.
From KScript.Queue These need <import package="KScript.Queue" />import KScript.Queue . See KScript.Queue .
The job to dispatch when the first job of the batch fails. Returns the batch, to chain.
Parameter Takes job required job
Example
.kscript XML Copy
<job name="Step" fields="n: int">
<fn name="handle"><if test="$n == 2"><do>@fail_job('bad row')</do></if></fn>
</job>
<job name="Report">
<fn name="handle"><echo>A step failed</echo></fn>
</job>
<let name="batch" value="@batch([Step(n: 1), Step(n: 2)])->catch(Report())->dispatch()" />
<echo>{ $batch.failed_count } failed</echo>.kscript XML Copy
job Step {
n: int
fn handle() {
if .n == 2 {
@fail_job('bad row')
}
}
}
job Report {
fn handle() {
echo 'A step failed'
}
}
$batch = @batch([Step(n: 1), Step(n: 2)])->catch(Report())->dispatch()
echo "{ $batch.failed_count } failed"# batch ->dispatch (queue?: string(min: 1) , connection?: string(min: 1) , after_commit?: bool ) → batch KScript.Queue Queues the batch's jobs and returns the batch, with its id. Inside a transaction it waits for the commit, as a job does. On the sync connection the jobs run now.
Parameter Takes queue optional string(min: 1) connection optional string(min: 1) after_commit optional a flag: after_commit or not after_commit
Arguments can be named: ->dispatch(…, connection: …, after_commit: …).
Example
.kscript XML Copy
<job name="Step" fields="n: int">
<fn name="handle"><echo>Step { $n }</echo></fn>
</job>
<let name="batch" value="@batch([Step(n: 1), Step(n: 2)])->dispatch()" />
<echo>{ $batch.processed } of { $batch.total }</echo>.kscript XML Copy
job Step {
n: int
fn handle() {
echo "Step { .n }"
}
}
$batch = @batch([Step(n: 1), Step(n: 2)])->dispatch()
echo "{ $batch.processed } of { $batch.total }"The job to dispatch once every job of the batch has run, whether or not they succeeded. Returns the batch, to chain.
Parameter Takes job required job
Example
.kscript XML Copy
<job name="Step" fields="n: int">
<fn name="handle"><echo>Step { $n }</echo></fn>
</job>
<job name="Tidy">
<fn name="handle"><echo>Tidied up</echo></fn>
</job>
<do>@batch([Step(n: 1)])->finally(Tidy())->dispatch()</do>.kscript XML Copy
job Step {
n: int
fn handle() {
echo "Step { .n }"
}
}
job Tidy {
fn handle() {
echo 'Tidied up'
}
}
@batch([Step(n: 1)])->finally(Tidy())->dispatch()The job to dispatch once every job of the batch has succeeded. Returns the batch, to chain.
Parameter Takes job required job
Example
.kscript XML Copy
<job name="Step" fields="n: int">
<fn name="handle"><echo>Step { $n }</echo></fn>
</job>
<job name="Done">
<fn name="handle"><echo>All done</echo></fn>
</job>
<do>@batch([Step(n: 1)])->then(Done())->dispatch()</do>.kscript XML Copy
job Step {
n: int
fn handle() {
echo "Step { .n }"
}
}
job Done {
fn handle() {
echo 'All done'
}
}
@batch([Step(n: 1)])->then(Done())->dispatch()Methods from any