Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Framework agnostic scheduler to run recurring jobs.

License

NotificationsYou must be signed in to change notification settings

bibendi/schked

Repository files navigation

Gem VersionBuild Status

Schked

Framework agnosticRufus-scheduler wrapper to run recurring jobs.

Sponsored by Evil Martians

Installation

Add this line to your application's Gemfile:

gem"schked"

And then execute:

bundle

Or install it yourself as:

gem install schked

Usage

Ruby on Rails

.schked

--require config/environment.rb

config/schedule.rb

cron"*/30 * * * *",as:"CleanOrphanAttachmentsJob",timeout:"60s",overlap:falsedoCleanOrphanAttachmentsJob.perform_laterend

If you have a Rails engine with own schedule:

engine-path/lib/foo/engine.rb

moduleFooclassEngine < ::Rails::Engineinitializer"foo"do |app|Schked.config.paths <<root.join("config","schedule.rb")endendend

And run Schked:

bundleexec schked start

To show schedule:

bundleexec schked show

Duplicate scheduling

When you deploy your schedule to production, you want to start new instance before you shut down the current. And you don't want simultaneous working of both. To achieve a seamless transition, Schked is using Redis for locks.

You can configure Redis client as the following:

Schked.config.redis={url:ENV.fetch("REDIS_URL")}

Callbacks

Also, you can define callbacks for errors handling:

config/initializers/schked.rb

Schked.config.register_callback(:on_error)do |job,error|Raven.capture_exception(error)ifdefined?(Raven)end

There are:before_start,:after_finish and:around_job callbacks as well.

Warning::before_start and:after_finish callbacks are executed in the scheduler thread, not in the work threads (the threads where the job execution really happens).

:around_job callback is executed in the job's thread.

Schked.config.register_callback(:around_job)do |job, &block|  ...block.call  ...end

Logging

By default Schked writes logs into stdout. In Rails environment Schked is using application logger. You can change it like this:

config/initializers/schked.rb

Schked.config.logger=Logger.new(Rails.root.join("log","schked.log"))

Monitoring

Yabeda::Schked - built-in metrics for monitoring Schked recurring jobs out of the box! Part of theyabeda suite.

Testing

describeSchkeddolet(:worker){described_class.worker.tap(&:pause)}arounddo |ex|Time.use_zone("UTC"){Timecop.travel(start_time, &ex)}enddescribe"CleanOrphanAttachmentsJob"dolet(:start_time){Time.zone.local(2008,9,1,10,42,21)}let(:job){worker.job("CleanOrphanAttachmentsJob")}specifydoexpect(job.next_time.to_local_time).toeqTime.zone.local(2008,9,1,11,0,0)endit"enqueues job"doexpect{job.call(false)}.tohave_enqueued_job(CleanOrphanAttachmentsJob)endendend

Contributing

Bug reports and pull requests are welcome on GitHub athttps://github.com/bibendi/schked. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to theContributor Covenant code of conduct.

License

The gem is available as open source under the terms of theMIT License.

Code of Conduct

Everyone interacting in the Schked project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow thecode of conduct.


[8]ページ先頭

©2009-2025 Movatter.jp