Skip to main content

No project description provided

Project description

rsq

Really Simple Queue is a really simple queue. It allows to push work in an async queue. Workers can consume that queue, and submit results.

Requirements

  • Mongo >= 3

Usage

Python

from traxix.rsq import RSQ, Const

# Init
rsq = RSQ(mongo_url="localhost")

# Push work
rsq.push(foo="bar")

# Get work
work = rsq.pull()

# Send result
rsq.done(_id=work[Const.ID], result=42)

Example (hello_world.py)

from traxix.rsq import RSQ, Const

# Init
rsq = RSQ(mongo_url="mongodb://172.17.0.2:27017", db_name="hello_word")

# Create 2 tasks
task_id_1 = rsq.push(payload=2)
task_id_2 = rsq.push(payload=3)

# List tasks
rsq.print_tasks()

while work := rsq.pull():
    print("pulled>", work)

    payload = work[Const.DATA]["payload"]
    if payload % 2 == 0:
        rsq.done(_id=work[Const.ID], result="even")
    else:
        # simulating a fail
        rsq.done(_id=work[Const.ID], success=False, result="odd")

    
# List tasks DONE
print("tasks>done>", rsq.list_tasks(state=Const.State.DONE))
print("tasks>fail>", rsq.list_tasks(state=Const.State.FAIL))

# cleanup
rsq.remove(_id=Const.REMOVE_EVERYTHING)

Cli

$ python3 rsq.py list_tasks
$ python3 rsq.py push --foo=bar 
61128c086f94b0d168e6a339
$ python3 rsq.py list_tasks
{'_id': ObjectId('61128c086f94b0d168e6a339'), 'state': 'todo', 'data': {'foo': 'bar'}}
$ python3 rsq.py pull -- -v # fire remove keys beginning with "_" hence the -v
_id: 61128c086f94b0d168e6a339
data: {"foo": "bar"}
$ python3 rsq.py done 61128c086f94b0d168e6a339 42
$ python3 rsq.py list_tasks
{'_id': ObjectId('61128c086f94b0d168e6a339'), 'state': 'done', 'data': {'foo': 'bar'}, 'result': 42}

Install

pip install traxix.rsq

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

traxix_rsq-0.2.8.tar.gz (6.7 kB view details)

Uploaded Source

File details

Details for the file traxix_rsq-0.2.8.tar.gz.

File metadata

  • Download URL: traxix_rsq-0.2.8.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for traxix_rsq-0.2.8.tar.gz
Algorithm Hash digest
SHA256 7b9f6e50a0f836fa4082167156cc1cdb6172109e4b8a739fbeeb30c5ddd7d377
MD5 b3647ba18c3710dba464134e6ba2f5ab
BLAKE2b-256 217683077132b178d279968449c3ab6749b597cc47778eb8fdaa78d4ec1a8b67

See more details on using hashes here.

Supported by

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