earl / beanstalkc

A simple beanstalkd client library for Python
Apache License 2.0
457 stars 115 forks source link

How to actively delete a delayed job before it is been consumed? #67

Open t0ny-peng opened 7 years ago

t0ny-peng commented 7 years ago

It's a quite weird question but it actually exists in my program. I'm designing a eBay like system, and the logic is that:

When users makes an order, they are required to pay within 30 minutes. Otherwise the order will be closed and the user cannot pay it anymore. I'm using a delayed job to realize this. Whenever an order is made, a job with 1800 seconds delay is generated. And if the user doesn't pay with 1800s, the job will be consumed to a python script, which marks the order as closed in database and notified the user.

But normally, 80% of the orders will be paid with in 1800s. Thus without these delayed jobs being deleted, 80% of the python computation is meaningless, and at least one mysql query will be executed for each job.

What I want to know, is how to actively delete the specific delayed job stored in an tube in my order logic. Like when the user finished the payment process, the delayed job will be deleted.