Skip to main content

Rewrite arq and make improvement.

Project description

ReArq

image image image image

Introduction

ReArq is a distributed task queue with asyncio and redis, which rewrite from arq to make improvement and include web interface.

You can try Demo Online here.

Screenshots

dashboard worker task job result

Requirements

  • Redis >= 5.0

Install

Use MySQL backend:

> pip install rearq[mysql]

Use PostgreSQL backend:

> pip install rearq[postgres]

Quick Start

Task Definition

# main.py
from rearq import ReArq
from rearq.server import models
from tortoise import Tortoise

rearq = ReArq()


@rearq.on_shutdown
async def on_shutdown():
    # you can do some clean work here like close db and so on...
    print("shutdown")


@rearq.on_startup
async def on_startup():
    # init tortoise
    await Tortoise.init(
        db_url=f"mysql://root:123456@127.0.0.1:3306/rearq",
        modules={"models": [models]},
    )
    # you should do some initialization work here, such tortoise-orm init and so on...
    print("startup")


@rearq.task(queue="myqueue")
async def add(self, a, b):
    return a + b


@rearq.task(cron="*/5 * * * * * *")  # run task per 5 seconds
async def timer(self):
    return "timer"

Run rearq worker

> rearq main:rearq worker -q myqueue
2021-03-29 09:54:50.464 | INFO     | rearq.worker:_main:95 - Start worker success with queue: rearq:queue:default
2021-03-29 09:54:50.465 | INFO     | rearq.worker:_main:96 - Registered tasks: add, sleep, timer_add
2021-03-29 09:54:50.465 | INFO     | rearq.worker:log_redis_info:86 - redis_version=6.2.1 mem_usage=1.43M clients_connected=5 db_keys=6

Run rearq timer

If you have timing task or delay task, you should run another command also:

> rearq main:rearq timer
2021-03-29 09:54:43.878 | INFO     | rearq.worker:_main:275 - Start timer success
2021-03-29 09:54:43.887 | INFO     | rearq.worker:_main:277 - Registered timer tasks: timer_add
2021-03-29 09:54:43.894 | INFO     | rearq.worker:log_redis_info:86 - redis_version=6.2.1 mem_usage=1.25M clients_connected=2 db_keys=6

Integration in FastAPI

from fastapi import FastAPI

app = FastAPI()


@app.on_event("startup")
async def startup() -> None:
    await rearq.init()


@app.on_event("shutdown")
async def shutdown() -> None:
    await rearq.close()


# then run task in view
@app.get("/test")
async def test():
    job = await add.delay(args=(1, 2))
    return job.info()

Start web interface

> rearq main:rearq server
Usage: rearq server [OPTIONS]

  Start rest api server.

Options:
  --host TEXT         Listen host.  [default: 0.0.0.0]
  -p, --port INTEGER  Listen port.  [default: 8000]
  -h, --help          Show this message and exit..

After server run, you can visit https://127.0.0.1:8000/docs to see all apis and https://127.0.0.1:8000 to see web interface.

ThanksTo

  • arq, Fast job queuing and RPC in python with asyncio and redis.

License

This project is under the MIT License.

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

rearq-0.2.6.tar.gz (29.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rearq-0.2.6-py3-none-any.whl (44.0 kB view details)

Uploaded Python 3

File details

Details for the file rearq-0.2.6.tar.gz.

File metadata

  • Download URL: rearq-0.2.6.tar.gz
  • Upload date:
  • Size: 29.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for rearq-0.2.6.tar.gz
Algorithm Hash digest
SHA256 fd61af82dcc3da76100473624de14856479b131bedcfe2df6cd12bfa44f634d5
MD5 1a5a01bcd53f1ae1304d605e721c3fa7
BLAKE2b-256 cdead68cf730f71374d7455c6ebea352d80da56f19c548e0bd690f749c6a5f44

See more details on using hashes here.

File details

Details for the file rearq-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: rearq-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 44.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for rearq-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 51f57a52efc40b8a008e41c4a971e26b2a4d81d155343a40d0efd3118ac4da28
MD5 fb8dba1a4dd212908cb3a2f06abfc91f
BLAKE2b-256 8387a65a203f31c1dbeb8521862851e2d0e3aadb3ba220476df45d36bb481b69

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