GithubHelp home page GithubHelp logo

pjongy / jasyncq Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 2.0 44 KB

High reliability asynchronous task queue using mysql

License: MIT License

Python 100.00%
asynchronous-tasks queue worker reliability mysql message-queue python3

jasyncq's Introduction

pjongy GitHub stats

jasyncq's People

Contributors

pjongy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

jasyncq's Issues

Task sequence (order)

Sometime there should be gone in order of each tasks.
For example, B task should be done after A regardless any task is between them like :
A ..K(independent).. B(depends on A)

Prob.
jasyncq does not support their ordering and but multiple consumers are supported.
In this case, below situation could be occurred.

  1. Publish task A
  2. Publish task K (indenpendent)
  3. Publish task B (depends on A)
  4. Worker 1 consumes ONE task (A fetched)
  5. Worker 2 consumes TWO task (K, B fetched)
  6. Worker 1 shutdowned (A task pended)
  7. Worker do their job (K- done, B - done (without A) )

Sol.
It can be solved by save tasks with their pre-done task number like:

| task_id | queued_at | depends_on |
|    A    |  2021-01  |            |
|    K    |  2021-02  |            |
|    B    |  2021-03  |     A      |

and fetch query can be:

# Does not fetch if depends_on id remains in task queue
SELECT child.*
  FROM queue_table as child
LEFT JOIN queue_table as parent
  ON child.depends_on=parent.uuid
WHERE parent.uuid IS NULL;

Result rows' will be returned if dependent task is already done or independent task.

Executing queries is slow

Executing just one query by joining all query list sql would be better than iterating for multiple queries. (It leass low performance.)

For example:

    async def _execute(self, queries: List[str]):
        async with self.pool.acquire() as conn:
            conn: Connection = conn  # NOTE(pjongy): For type hinting
            async with conn.cursor() as cur:
                cur: Cursor = cur  # NOTE(pjongy): For type hinting
                await cur.execute(';'.join(queries))
                await conn.commit()

is better than it

cur: Cursor = cur # NOTE(pjongy): For type hinting
[
await cur.execute(clause)
for clause in queries
]
await conn.commit()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.