hummingbird-project / swift-jobs

Offload work your server would be doing to another server
Apache License 2.0
14 stars 2 forks source link

Delayed Jobs and Retry Jobs with Backoff #22

Closed thoven87 closed 1 month ago

thoven87 commented 2 months ago

I wanted to open this ticket to discuss the proposal for adding both delayed and retry jobs with exponential backoff.

I think both delayed and retry with backoff are similar in that they can be scheduled to be executed at a later date.

Looking at the diagrams below, I think we can put both features in the same category.

delayed-vs-rety-job-2

The Postgres implementation is the easier out of three JobQueue drivers currently available (Memory, Postgres, Redis)

1 - Postgres Driver:

I am proposing of adding one more column to the _hb_pg_jobs table called scheduled_at with Nullable value.

2 - Redis Driver:

This will require one of two new row keys swift_jobs::scheduled::${JobID} and swift_jobs::ready${JobID} we can use Redis scripts to atomically move jobs from state (scheduled) to another state(ready). I am not too familiar with the RedisStack yet to know of this limitation.

I welcome some feedback on how to proceed further @adam-fowler @Joannis

adam-fowler commented 1 month ago

I think you can build the retry with back off on top of delayed jobs. That is why I was suggesting we do a PR for delayed jobs first. Once we are happy with that we can implement the retry with back off.

Regarding the implementation we would need to separate the delay out from the data passed to the job driver as the different drivers will need access to this value.

adam-fowler commented 1 month ago

Regarding drivers, yeah Postgres is easy. I also think the memory one is easy enough as well. A Redis script could be used for moving delayed jobs, but we'd have to be careful it doesn't lock the database too long. I am also a little concerned about moving logic onto the redis server.

thoven87 commented 1 month ago

First pass of delayed job implementation here I will follow up with the Postgres Driver then Redis.

thoven87 commented 1 month ago

I think we can close this ticket now!