Schdlr
A minimal library for scheduling jobs for later execution.
Installation
Add this line to your application's Gemfile:
gem 'schdlr', git: 'https://github.com/devsfutter/schdlr.git'
And then execute:
$ bundle
Usage
class Job < Schdlr::Job
attr_accessor :id
def perform
puts "#{Time.now}: Job2 doing something with id: ##{id}"
return true
end
end
class JobThatFail < Schdlr::Job
attr_accessor :id
def perform
puts "#{Time.now}: JobThatFail doing something with id: ##{id}"
fail!('missing argument :id') if id.nil?
end
end
@queue = Schdlr::Queue::Sqlite.new
@schhlr = Schdlr.new(@queue)
job1 = Job.new(id: '12344')
job2 = JobThatFail.new
@schhlr.now(job1) #=> schhlr.at(Time.now, job1)
at_time = Time.new(2019,2,2)
@schhlr.at(at_time, job2)
#Start processing queue
@schhlr.start!
# => 2019-01-27 13:40:21 +0100: Job2 doing something with id: #12344
# (time passes by)
# => 2019-02-02 00:00:00 +0100: JobThatFail doing something with id: #
#Stop processing queue
@schhlr.stop!
TODO
- [ ] Failed tasks stays in the queue, they should have a status to avoid retrying failed tasks.
- [ ] Improve test suite.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/devsfutter/schdlr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Schdlr project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.