zhong 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/zhong/at.rb +4 -4
- data/lib/zhong/scheduler.rb +1 -4
- data/lib/zhong/version.rb +1 -1
- data/lib/zhong/web.rb +4 -0
- data/test/test_at.rb +7 -1
- data/test/test_library.rb +8 -1
- data/test/test_scheduler.rb +11 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8e24ce8cbfc3ebd6b0574c791aef211bb0777c1
|
4
|
+
data.tar.gz: cd327270c61bbfb6817096ff5e2f2aee1ade850e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5955bed476e79f2b79520523724320404733986912bda9d3d6fc1396c578a935336fd2927295579f9bfe838baf2ee4d55ff953ab6a0f5f4332d3afb85ad0678
|
7
|
+
data.tar.gz: e8082120c278422e3d1f04660739877d4d7fba6573745c31f63df0df4116d719a424087e1d3b8ac06d863d1dd0c98ebfd3489a7e411dcebe08228a1c6fc07ec4
|
data/CHANGELOG.md
CHANGED
data/lib/zhong/at.rb
CHANGED
@@ -71,6 +71,10 @@ module Zhong
|
|
71
71
|
MessagePack.pack(as_json)
|
72
72
|
end
|
73
73
|
|
74
|
+
def ==(other)
|
75
|
+
other.class == self.class && other.state == state
|
76
|
+
end
|
77
|
+
|
74
78
|
def self.parse_serialized(at)
|
75
79
|
if at.is_a?(Array)
|
76
80
|
MultiAt.new(at.map { |a| parse_serialized(a) })
|
@@ -114,10 +118,6 @@ module Zhong
|
|
114
118
|
end
|
115
119
|
end
|
116
120
|
|
117
|
-
def ==(other)
|
118
|
-
other.class == self.class && other.state == state
|
119
|
-
end
|
120
|
-
|
121
121
|
def state
|
122
122
|
[@minute, @hour, @wday]
|
123
123
|
end
|
data/lib/zhong/scheduler.rb
CHANGED
@@ -45,10 +45,7 @@ module Zhong
|
|
45
45
|
|
46
46
|
job = Job.new(name, opts.merge(@config).merge(every: period, category: @category), &block)
|
47
47
|
|
48
|
-
if jobs.key?(job.id)
|
49
|
-
@logger.error "duplicate job #{job}, skipping"
|
50
|
-
return
|
51
|
-
end
|
48
|
+
raise "duplicate job #{job}" if jobs.key?(job.id)
|
52
49
|
|
53
50
|
@jobs[job.id] = job
|
54
51
|
end
|
data/lib/zhong/version.rb
CHANGED
data/lib/zhong/web.rb
CHANGED
@@ -10,6 +10,7 @@ module Zhong
|
|
10
10
|
enable :sessions
|
11
11
|
use ::Rack::Protection, use: :authenticity_token unless ENV["RACK_ENV"] == "test"
|
12
12
|
|
13
|
+
# :nocov:
|
13
14
|
if ENV["ZHONG_WEB_USERNAME"] && ENV["ZHONG_WEB_PASSWORD"]
|
14
15
|
use Rack::Auth::Basic, "Sorry." do |username, password|
|
15
16
|
username == ENV["ZHONG_WEB_USERNAME"] and password == ENV["ZHONG_WEB_PASSWORD"]
|
@@ -21,6 +22,7 @@ module Zhong
|
|
21
22
|
STDERR.puts "[params] #{params}" unless params.empty?
|
22
23
|
end
|
23
24
|
end
|
25
|
+
# :nocov:
|
24
26
|
|
25
27
|
set :root, File.expand_path(File.dirname(__FILE__) + "/../../web")
|
26
28
|
set :public_folder, proc { "#{root}/assets" }
|
@@ -69,10 +71,12 @@ if defined?(::ActionDispatch::Request::Session) && !::ActionDispatch::Request::S
|
|
69
71
|
# mperham/sidekiq#2460
|
70
72
|
# Rack apps can't reuse the Rails session store without
|
71
73
|
# this monkeypatch
|
74
|
+
# :nocov:
|
72
75
|
class ActionDispatch::Request::Session
|
73
76
|
def each(&block)
|
74
77
|
hash = self.to_hash
|
75
78
|
hash.each(&block)
|
76
79
|
end
|
77
80
|
end
|
81
|
+
# :nocov:
|
78
82
|
end
|
data/test/test_at.rb
CHANGED
@@ -159,12 +159,18 @@ class TestAt < Minitest::Test
|
|
159
159
|
assert_equal([{m: nil, h: 8, w: nil, g: 0.seconds}, {m: 30, h: 12, w: 0, g: 0.seconds}], at.as_json)
|
160
160
|
end
|
161
161
|
|
162
|
-
def
|
162
|
+
def test_serialize_multi
|
163
163
|
at = Zhong::At.parse(["8:20", "tues 12:30"])
|
164
164
|
|
165
165
|
assert_equal Zhong::At.deserialize(at.serialize), at
|
166
166
|
end
|
167
167
|
|
168
|
+
def test_serialize_single
|
169
|
+
at = Zhong::At.parse("sun 14:20")
|
170
|
+
|
171
|
+
assert_equal Zhong::At.deserialize(at.serialize), at
|
172
|
+
end
|
173
|
+
|
168
174
|
def test_invalid_time_32
|
169
175
|
assert_raises Zhong::At::FailedToParse do
|
170
176
|
Zhong::At.parse("32:00")
|
data/test/test_library.rb
CHANGED
@@ -10,12 +10,19 @@ class TestLibrary < Minitest::Test
|
|
10
10
|
sleep 1
|
11
11
|
end
|
12
12
|
|
13
|
+
def test_logger
|
14
|
+
test_logger = Zhong.logger
|
15
|
+
Zhong.logger = nil
|
16
|
+
assert_output(nil, nil) { Zhong.logger.info "ensure has default logger" }
|
17
|
+
Zhong.logger = test_logger
|
18
|
+
end
|
19
|
+
|
13
20
|
def test_heartbeats
|
14
21
|
Zhong.schedule { nil }
|
15
22
|
t = Thread.new { Zhong.start }
|
16
23
|
sleep(1)
|
17
24
|
assert_equal true, Zhong.any_running?
|
18
|
-
assert_in_delta Zhong.redis_time.to_f, Time.now.to_f,
|
25
|
+
assert_in_delta Zhong.redis_time.to_f, Time.now.to_f, 1
|
19
26
|
assert_in_delta Zhong.redis_time.to_f, Zhong.latest_heartbeat.to_f, 1
|
20
27
|
Zhong.stop
|
21
28
|
t.join
|
data/test/test_scheduler.rb
CHANGED
@@ -44,6 +44,17 @@ class TestScheduler < Minitest::Test
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
def test_duplicate_job_name
|
48
|
+
boom = assert_raises RuntimeError do
|
49
|
+
Zhong.schedule do
|
50
|
+
every(1.second, "dupe_job") { nil }
|
51
|
+
every(1.second, "dupe_job") { nil }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_match(/duplicate job dupe_job/, boom.message)
|
56
|
+
end
|
57
|
+
|
47
58
|
def test_scheduler_callbacks
|
48
59
|
test_before_tick = 0
|
49
60
|
test_after_tick = 0
|