#job->dispatch(delay?: duration, at?: date, queue?: string(min: 1), connection?: string(min: 1), after_commit?: bool) → map KScript.Queue
将任务入队并返回入队的内容:{ id, job, queue, connection, available_at }。delay(10m)或 at(某个日期)可使其延迟执行;如果唯一任务已在队列中,则返回 null。在事务内,任务会在提交时入队,若回滚则丢弃;未使用 after_commit 时则立即入队。
| 参数 | 接受 |
|---|---|
delay 可选 | duration |
at 可选 | date |
queue 可选 | string(min: 1) |
connection 可选 | string(min: 1) |
after_commit 可选 | 标志:after_commit 或 not after_commit |
参数可以命名:->dispatch(…, at: …, queue: …)。
示例
<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