GithubHelp home page GithubHelp logo

litements / litequeue Goto Github PK

View Code? Open in Web Editor NEW
163.0 5.0 7.0 78 KB

Queue built on top of SQLite

Home Page: https://litements.polyrand.net/queue/

License: MIT License

Python 62.93% Jupyter Notebook 33.71% Makefile 3.35%
sql python sqlite queue message persitent

litequeue's People

Contributors

ifduyue avatar nische avatar polyrand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

litequeue's Issues

bytes is also supported

Hello,

def put(self, data: str) -> Message:

Annotation is str, but bytes works, maybe change annotation to str|bytes?

In [1]: from litequeue import LiteQueue

In [2]: q = LiteQueue(memory=True)

In [3]: q.put('a')
Out[3]: Message(data='a', message_id='0667127d-c488-75f4-8000-9b1e8b8dbb25', status=<MessageStatus.READY: 0>, in_time=1718691804283328000, lock_time=None, done_time=None)

In [4]: q.put(b'a')
Out[4]: Message(data=b'a', message_id='0667127e-00ab-7d4c-8000-47674cc35d04', status=<MessageStatus.READY: 0>, in_time=1718691808041979000, lock_time=None, done_time=None)

In [5]: q.pop()
Out[5]: Message(data='a', message_id='0667127d-c488-75f4-8000-9b1e8b8dbb25', status=1, in_time=1718691804283328000, lock_time=1718691813868331000, done_time=None)

In [6]: q.pop()
Out[6]: Message(data=b'a', message_id='0667127e-00ab-7d4c-8000-47674cc35d04', status=1, in_time=1718691808041979000, lock_time=1718691814732661000, done_time=None)

In [7]: q.pop()

Is there any retry mechanism for items that haven't been marked done?

Firstly, thank you very much for making this open source project.

I was wondering if there is any retry mechanism for items that haven't been marked done explicitly?

If you pop item, then this happen:
UPDATE Queue SET status = 1, lock_time = strftime('%s','now') WHERE message_id = ? and status =0

When you mark item as done then this happen:
UPDATE Queue SET status = 2, done_time = strftime('%s','now') WHERE message_id = ?

... but if the queue worker fails and doesn't mark item done, what happens next? Would the item with status=1 stay forever in the queue?

Question: Can this be used across processes?

I read the source code and I think using EXCLUSIVE transactions, the answer is affirmative, but can I have one Python process running that adds to the queue then multiple others reading and working? It would have to rely on sqlite's locking but I think the transaction does that.

What are the guarantees of _pop_transaction? Same item being returned twice race condition, possible?

I am looking on the _pop_transaction and wondering how it works and what guarantees it has.

In order for it to pop the item it executes this:

BEGIN IMMEDIATE

SELECT message, message_id FROM Queue
            WHERE rowid = (SELECT min(rowid) FROM Queue
                           WHERE status = 0)

UPDATE Queue SET status = 1, lock_time = strftime('%s','now') WHERE message_id = :message_id AND status = 0

Assuming there is more than one worker that pops the items from the queue, is it possible for them to SELECT the same message_id? If that happens then they would both try to UPDATE the status to 1.
Only one of them would actually do the actual row update, since there is WHERE status = 0 check, so the first UPDATE wins... but in fact shouldn't the code check the result: select changes(); to discard the item which actually hasn't effectively updated DB?

What's the role of IMMEDIATE locking here by the way? I've just started looking on the SQLite project and come from the MySQL background, pardon my lack of experience.

Is there any priority queue implemented here?

im new to these message queue and after skimming the docs as far as i know, i need to implement this by priority therefore a priority queue not a normal queue. or maybe im missing something?

ratelimit

Is it possible for this thing to implement a ratelimit mechanism?
like node js p-queue

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.