Relay.Task

View as Markdown

Relay.Task

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.

1from signalwire.relay.task import Task
2
3task = Task(project='<my-project>', token='<my-token>')
4success = task.deliver('context-here', { 'key': 'random data' })

Methods

deliver

Send a job to your Consumer in a specific context.

Parameters

ParameterTypeRequiredDescription
contextstringrequiredContext where to send the Task.
messagedictrequiredDict with your custom data that will be sent to your Consumer's onTask method.

Returns

coroutine - Coroutine that will be fulfilled with a boolean value.

Examples

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

1from signalwire.relay.task import Task
2
3project = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
4token = 'PTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
5task = Task(project=project, token=token)
6data = {
7 'action': 'call',
8 'from': '+18881112222'
9 'to': '+18881113333'
10}
11success = task.deliver('office', data)
12if success:
13 print('Task delivered')
14else:
15 print('Task not delivered')