Giter VIP home page Giter VIP logo

Comments (13)

tobymao avatar tobymao commented on September 16, 2024

can you explain why it won’t work?

from saq.

markus-zoezi avatar markus-zoezi commented on September 16, 2024

First I add one job and let it run for a few seconds, then abort it and enqueue a new one with the same key. The log looks like this:

INFO:saq:Processing Job<...
INFO:saq:Finished Job<...
INFO:saq:Aborting saq:job...

There is no new Processing-line after the Aborting-line.

from saq.

tobymao avatar tobymao commented on September 16, 2024

can you give me a reproducible code snippet? it seems like you’re using key wrong. key is used to guarantee that there are no duplicate jobs. you probably shouldn’t use key

closing for now but if you provide a code snippet that i can repro it i’ll take a look.

from saq.

markus-zoezi avatar markus-zoezi commented on September 16, 2024

This is worker.py started with python3 -m saq worker.settings -v -v -v

import asyncio, os
from saq import Queue
import logging
logger = logging.getLogger("saq")

async def test(ctx):
    logger.info('Starting job. sleeping for 10 seconds')
    await asyncio.sleep(10)
    logger.info('Done sleeping')

queue = Queue.from_url(os.getenv('REDIS'))

settings = {
    "queue": queue,
    "functions": [test],
    "concurrency": 2
}

And this is used to add jobs. Run it twice in a row:

import asyncio, os
from saq import Job, Queue

async def main():
    queue = Queue.from_url(os.getenv('REDIS'))

    job = await queue.job('test')
    if job:
        print('Aborting')
        await queue.abort(job, 'New build task added')

    print('Adding task')
    await queue.enqueue(Job(key='test', function='test'))

if __name__ == "__main__":
    asyncio.run(main())

from saq.

tobymao avatar tobymao commented on September 16, 2024

how quickly are you running it twice in a row? the abort has a 5 second ttl

from saq.

markus-zoezi avatar markus-zoezi commented on September 16, 2024

Immediately after the first add I run the second add

from saq.

tobymao avatar tobymao commented on September 16, 2024

there’s a 5 second window where you can’t readd something you aborted, it’s an option in the abort method

from saq.

markus-zoezi avatar markus-zoezi commented on September 16, 2024

Ok I see. What is your suggestion on how to do this? Set ttl to 0? Or some other way?

from saq.

tobymao avatar tobymao commented on September 16, 2024

ttl 0 won’t work because then it won’t get aborted. i suggest not using a key.

from saq.

markus-zoezi avatar markus-zoezi commented on September 16, 2024

I use the key so that I can find the job to see if there is already an ongoing job, and abort it. If it's a random id, I'd have to store that Job id someplace and keep track of that. Unless there is some other way to loop through all future jobs and check their arguments or something.

from saq.

tobymao avatar tobymao commented on September 16, 2024

then you need to check that a job is actually aborted before enqueuing the next job

from saq.

markus-zoezi avatar markus-zoezi commented on September 16, 2024

How do you mean I can check that? Can you give me an example?

from saq.

tobymao avatar tobymao commented on September 16, 2024

check the job status

from saq.

Related Issues (20)

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.