oldmoe / litestack

MIT License
1.11k stars 59 forks source link

Litejob doesn't retry jobs on failure #7

Closed ttilberg closed 1 year ago

ttilberg commented 1 year ago

I look forward to implementation of job retries.

/tmp/litestack-demo
▶ pry
[1] pry(main)> require 'litestack'
=> true
[2] pry(main)> require 'sequel'
=> true
[3] pry(main)> class Job
[3] pry(main)*   include Litejob
[3] pry(main)*   def perform(args={})
[3] pry(main)*     puts "Starting job at #{Time.now}"
[3] pry(main)*     sleep 3
[3] pry(main)*     puts "Blowing up: #{Time.now}"
[3] pry(main)*     raise "Well shucks."
[3] pry(main)*   end
[3] pry(main)* end
=> :perform
[4] pry(main)> q = Sequel.connect('litedb://queue.db')
=> #<Sequel::Litedb::Database: "litedb://queue.db">
[5] pry(main)> q.tables
=> [:_ul_queue_]
[6] pry(main)> q[:_ul_queue_].all
=> []
[7] pry(main)> Job.perform_async
I, [2023-03-06T16:17:06.157153 #92521]  INFO -- : [litejob]:[ENQ] id: 1678141026-F04E622CB1A83B6E615.6 class: Job
=> "1678141026-F04E622CB1A83B6E615.6"
[8] pry(main)> I, [2023-03-06T16:17:06.450876 #92521]  INFO -- : [litejob]:[DEQ] id: 1678141026-F04E622CB1A83B6E615.6 class: Job
Starting job at 2023-03-06 16:17:06 -0600
[8] pry(main)> q[:_ul_queue_].all
=> []
[9] pry(main)> Blowing up: 2023-03-06 16:17:09 -0600
Well shucks.
Well shucks.
(pry):9:in `perform'
           # < snip >
[9] pry(main)>
[10] pry(main)>
[11] pry(main)> q[:_ul_queue_].all
=> []
[12] pry(main)>
oldmoe commented 1 year ago

Hi, this should be coming soon, stay tuned

oldmoe commented 1 year ago

I have a skeleton implementation on my local branch, this will respect the following options: retries: the number of retries before failing permanently, default is 5 retries retry_delay: delay before the job is attempted again, default is 60 seconds retry_delay_factor: exponential growth factor for the delay, default is 10, i.e. 60 then 600, then 6000 seconds

At the moment jobs that fail permanently are just logged (you can set the logger to filename destination in options) and are gone forever from the database. This can of course be changed later.

Would like to get your feedback and if you think there are any glaring omissions (besides the job being lost after failures are exhausted)

oldmoe commented 1 year ago

The new version implements a retry mechanism, more details available in the Litejob guide