Module: Hutch::Schedule
- Defined in:
- lib/hutch/schedule.rb,
lib/hutch/schedule/core.rb,
lib/hutch/schedule/version.rb
Overview
Hutch::Schedule, just an addon to deal with the schedule exchange. If you want use it, just do ‘Hutch::Schedule.connect(Hutch.broker)` to initialize it and then just use like Hutch to publish message `Hutch::Schedule.publish`
Defined Under Namespace
Classes: Core
Constant Summary collapse
- DELAY_QUEUES =
fixed delay levels seconds(4): 5s, 10s, 20s, 30s minutes(14): 1m, 2m, 3m, 4m, 5m, 6m, 7m, 8m, 9m, 10m, 20m, 30m, 40m, 50m hours(3): 1h, 2h, 3h
%w(5s 10s 20s 30s 60s 120s 180s 240s 300s 360s 420s 480s 540s 600s 1200s 1800s 2400s 3000s 3600s 7200s 10800s)
- VERSION =
"0.7.2"
Class Method Summary collapse
- .connect ⇒ Object
- .core ⇒ Object
- .delay_queue_name(suffix) ⇒ Object
-
.delay_routing_key(suffix) ⇒ Object
fixed delay level queue’s routing_key.
- .disconnect ⇒ Object
-
.ns ⇒ Object
redis with namespace.
- .publish(*args) ⇒ Object
-
.redis ⇒ Object
all Consumers that use threshold module shared the same redis instance.
Class Method Details
.connect ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/hutch/schedule.rb', line 29 def connect ActiveJob::QueueAdapters::HutchAdapter.register_actice_job_classes if defined?(ActiveJob::QueueAdapters::HutchAdapter) return if core.present? Hutch.connect @core = Hutch::Schedule::Core.new(Hutch.broker) @core.connect! end |
.core ⇒ Object
43 44 45 |
# File 'lib/hutch/schedule.rb', line 43 def core @core end |
.delay_queue_name(suffix) ⇒ Object
74 75 76 |
# File 'lib/hutch/schedule.rb', line 74 def delay_queue_name(suffix) "#{Hutch::Config.get(:mq_exchange)}_delay_queue_#{suffix}" end |
.delay_routing_key(suffix) ⇒ Object
fixed delay level queue’s routing_key
70 71 72 |
# File 'lib/hutch/schedule.rb', line 70 def delay_routing_key(suffix) "#{Hutch::Config.get(:mq_exchange)}.schedule.#{suffix}" end |
.disconnect ⇒ Object
38 39 40 41 |
# File 'lib/hutch/schedule.rb', line 38 def disconnect Hutch.disconnect if Hutch.connected? @core = nil end |
.ns ⇒ Object
redis with namespace
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/hutch/schedule.rb', line 48 def ns @redis ||= Redis::Namespace.new(:hutch, redis: Redis.new( url: Hutch::Config.get(:redis_url), # https://github.com/redis/redis-rb#reconnections # retry 10 times total cost 10 * 30 = 300s reconnect_attempts: Hutch::Config.get(:ratelimit_redis_reconnect_attempts), :reconnect_delay => 3, :reconnect_delay_max => 30.0, )) end |
.publish(*args) ⇒ Object
65 66 67 |
# File 'lib/hutch/schedule.rb', line 65 def publish(*args) core.publish(*args) end |
.redis ⇒ Object
all Consumers that use threshold module shared the same redis instance
60 61 62 |
# File 'lib/hutch/schedule.rb', line 60 def redis ns.redis end |