Skip to main content

Multithreaded Google Task Queue client.

Project description

# python-task-queue
Python TaskQueue object that can rapidly populate and download from queues that conform to Google's Task Queue API

# Installation

`pip install taskqueue`

# Usage

Define a class that inherits from taskqueue.RegisteredTask and implments the `execute` method.

Tasks can be loaded into queues locally or as based64 encoded data in the cloud and executed later.
Here's an example implementation of a `PrintTask`. Generally, you should specify a very lightweight
container and let the actual execution download and manipulate data.

```
class PrintTask(RegisteredTask):
def __init__(self, txt=''):
super(PrintTask, self).__init__()
self.txt = txt
def execute(self):
if self.txt:
print(str(self) + ": " + str(self.txt))
else:
print(self)
```

## Local Usage

For small jobs, you might want to use one or more processes to execute the tasks:
```
with LocalTaskQueue(parallel=5) as tq: # use 5 processes
for _ in range(1000):
tq.insert(
PrintTask(i)
)
```
This will load the queue with 1000 print tasks then execute them across five processes.

## Cloud Usage

Set up an SQS queue and acquire an aws-secret.json that is compatible with CloudVolume.

```
qurl = 'https://sqs.us-east-1.amazonaws.com/$DIGITS/$QUEUE_NAME'
with TaskQueue(queue_server='sqs', qurl=qurl) as tq:
for _ in range(1000):
tq.insert(PrintTask(i))
```

This inserts 1000 PrintTask descriptions into your SQS queue.

Somewhere else, you'll do the following (probably across multiple workers):

```
qurl = 'https://sqs.us-east-1.amazonaws.com/$DIGITS/$QUEUE_NAME'
with TaskQueue(queue_server='sqs', qurl=qurl) as tq:
task = tq.lease(seconds=int($LEASE_SECONDS))
task.execute()
tq.delete(task)
```



Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

task-queue-0.6.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

task_queue-0.6.0-py2.py3-none-any.whl (11.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file task-queue-0.6.0.tar.gz.

File metadata

  • Download URL: task-queue-0.6.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for task-queue-0.6.0.tar.gz
Algorithm Hash digest
SHA256 8c078beee7def2756ae305b85ad6c03830e18c4dbf8ecff719eb7747d73ed1b0
MD5 470d8011c3db463eda278ca69d7582ee
BLAKE2b-256 315587d77389a06211a06404f5aed81348a327c94c6b6ee4ec927fb5cc149057

See more details on using hashes here.

File details

Details for the file task_queue-0.6.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for task_queue-0.6.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5c80936cb751cbe5147e135ffb453ad0e383e8b23a73e30d8b1b4c432051b0e2
MD5 ae28579ae8a98f0a717d197b04fcb127
BLAKE2b-256 6447fe2b19299455d6430dca59fe1c0121295fdf7a10e6c9c9ad205874546bb8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page