Relay.Task

View as Markdown

A Relay.Task is simple way to send jobs to your Relay.Consumers from a short lived process, like a web framework. RELAY Tasks allow you to pass commands down to your Consumers without blocking your short lived request. Think of a RELAY Task as a way to queue a job for your background workers to processes asynchronously.

Creating Tasks

A Task is a simple object with 2 required arguments: $project and $token. Project and Token are used to send the Task to your Consumers. Once created, the Task has only one method deliver to send jobs to your Consumer.

1<?php
2
3require dirname(__FILE__) . '/vendor/autoload.php';
4
5use SignalWire\Relay\Tasking\Task;
6
7$task = new Task('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', 'PTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
8$context = 'office';
9$delivered = $task->deliver($context, [
10 'key' => 'value',
11 'data' => 'data for your job'
12]);

Methods

deliver

Send a job to your Consumer in a specific context.

Parameters

ParameterTypeRequiredDescription
$contextstringrequiredContext where to send the Task.
$messagearrayrequiredArray with your custom data that will be sent to your Consumer’s onTask handler.

Returns

boolean - Whether the Task has been sent successfully.

Examples

Deliver a task to your Consumer with a message to then make an outbound Call.

1<?php
2
3$delivered = $task->deliver('office', [
4 'action' => 'call',
5 'from' => '+18881112222'
6 'to' => '+18881113333'
7]);