一度の/周期的なイベントスケジューラのライブラリのひとつ。
-
条件指定された日時に一度だけまたは周期的に動作するスレッドベースのスケジューラ.
-
条件は crontab のような書式や、キーワード引数で指定する.
-
時刻は1秒未満で指定することが可能. ただし、挙動は環境依存.
-
一時停止/再開機能.
-
実行中の日時条件変更機能.
-
指定された制限時間内に一度だけ実行する.
アプリの Gemfile にこの行を追加
gem 'time_scheduler'
それから実行
$ bundle install
または次のように手動で導入
$ gem install time_scheduler or $ gem install -l time_scheduler-x.x.x.gem
require "time_scheduler"
Scheduler = TimeScheduler.new
Signal.trap( :INT ) do
exit
end
goal = Time.now + 5
while time = Scheduler.wait( sec: "*" )
p time
break if time > goal
end
goal = Time.now + 5
Scheduler.wait( :check, sec: "*" ) do |time|
p time
Scheduler.cancel( :check ) if time > goal
end
sleep 10
require "time_scheduler"
Scheduler = TimeScheduler.new
Signal.trap( :INT ) do
exit
end
Scheduler.wait( sec: "*/5" ) do |time|
p [time, :sec5]
end
Scheduler.wait( cron: "*/2 * * * *" ) do |time|
p [time, :cron]
end
Scheduler.wait( at: Time.now + 30 ) do |time|
p [time, :quit]
exit
end
sleep
TimeScheduler#wait( topic = Time.now.iso8601(6),
at: nil, cron: nil, year: nil, month: nil, day: nil, wday: nil,
hour: nil, min: nil, sec: 0, msec: nil,
&block )
-
Result:
-
ブロック引数あり: (Non-blocing Mode)
-
topic. イベント操作用識別トピック.
-
-
ブロック引数なし: (Blocking Mode)
-
time. イベント日時. Time オブジェクト.
-
-
-
Parameter:
-
topic: イベント操作用識別トピック (default: Time.now.iso8601(6))
-
at: 日時. Time または String オブジェクト. (default: nil)
-
cron: 分、時、日、月、曜パターンのセット. (default: nil)
-
year: 年. 範囲制限なしは拒否される. (default: nil)
-
month: 月. 1..12, jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec. (default: nil)
-
day: 日. 1..31. (default: nil)
-
wday: 曜. 0..7, sun, mon, tue, wed, thr, fri, sat. (default: nil)
-
hour: 時. 0..23. (default: nil)
-
min: 分. 0..59. (default: nil)
-
sec: 秒. 0..59. (default: 0)
-
msec: ミリ秒. 0..999. (default: nil), ミリ秒が指定されたとき, 他のパラメータは無視される. 詳細では, ワイルドカードとして "*" を使用できる.
-
block: 条件に適合する日時に実行する内容.
-
-
Block Parameter:
-
time: イベント日時. Time オブジェクト.
-
TimeScheduler#first_only( ident = nil, timeout: 1, &block )
-
Result:
-
nil.
-
-
Parameter:
-
ident: 追加識別子.
-
timeout: 監視時間制限(秒).
-
-
Block Parameter:
-
なし.
-
不具合報告とプルリクエストは GitHub https://github.com/arimay/time_cursor まで.
この Gem は、 MITライセンス の条件に基づいてオープンソースとして入手できる.
Copyright (c) ARIMA Yasuhiro <arima.yasuhiro@gmail.com>