zhong 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -2
- data/lib/zhong/scheduler.rb +15 -7
- data/lib/zhong/version.rb +1 -1
- data/lib/zhong/web.rb +6 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6786d80a0d2da5fc3d4605ab95a511764b96e2e6
|
4
|
+
data.tar.gz: 2c1f61feff58195e3e8521b7d965f0cb7ed0d616
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e9b281a5edbd9a6aa9c99ecff01b24f153c886ea2bf91d4659cf92ef858da518e5d96f18ce9b7e253372dc07e8749289fddff77104e72cd61df056fa72d9028
|
7
|
+
data.tar.gz: e0c854e2d554048f88fa4368701c2d59e7e40dccb2d2165f43df3d9ffd679c382c485b1b2f566617a1de0dd17657aef9f2ed07d9f93bb394f6e3abcf9dbdcf85
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -34,7 +34,7 @@ Zhong.schedule do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
# note: callbacks that
|
37
|
+
# note: callbacks that explicitly false will cause event to not run
|
38
38
|
on(:before_tick) do
|
39
39
|
puts "ding"
|
40
40
|
true
|
@@ -42,7 +42,6 @@ Zhong.schedule do
|
|
42
42
|
|
43
43
|
on(:after_tick) do
|
44
44
|
puts "dong"
|
45
|
-
true
|
46
45
|
end
|
47
46
|
|
48
47
|
on(:before_run) do |job, time|
|
data/lib/zhong/scheduler.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Zhong
|
2
2
|
class Scheduler
|
3
|
-
attr_reader :config, :redis, :jobs
|
3
|
+
attr_reader :config, :redis, :jobs, :logger
|
4
4
|
|
5
5
|
DEFAULT_CONFIG = {
|
6
6
|
timeout: 0.5,
|
@@ -61,7 +61,7 @@ module Zhong
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def start
|
64
|
-
|
64
|
+
logger.info "starting at #{redis_time}"
|
65
65
|
|
66
66
|
@stop = false
|
67
67
|
|
@@ -87,19 +87,22 @@ module Zhong
|
|
87
87
|
heartbeat(now)
|
88
88
|
|
89
89
|
break if @stop
|
90
|
-
|
90
|
+
else
|
91
|
+
logger.info "skipping tick due to a `:before_tick` callback"
|
91
92
|
end
|
92
93
|
|
94
|
+
sleep_until_next_second
|
95
|
+
|
93
96
|
break if @stop
|
94
97
|
end
|
95
98
|
|
96
99
|
@running = false
|
97
100
|
|
98
|
-
Thread.new {
|
101
|
+
Thread.new { logger.info "stopped" }.join
|
99
102
|
end
|
100
103
|
|
101
104
|
def stop
|
102
|
-
Thread.new {
|
105
|
+
Thread.new { logger.error "stopping" } if @running # thread necessary due to trap context
|
103
106
|
@stop = true
|
104
107
|
end
|
105
108
|
|
@@ -119,7 +122,9 @@ module Zhong
|
|
119
122
|
private_constant :TRAPPED_SIGNALS
|
120
123
|
|
121
124
|
def fire_callbacks(event, *args)
|
122
|
-
@callbacks[event].to_a.
|
125
|
+
@callbacks[event].to_a.map do |callback|
|
126
|
+
callback.call(*args)
|
127
|
+
end.compact.all? # do not skip on nils
|
123
128
|
end
|
124
129
|
|
125
130
|
def jobs_to_run(time = redis_time)
|
@@ -127,7 +132,10 @@ module Zhong
|
|
127
132
|
end
|
128
133
|
|
129
134
|
def run_job(job, time = redis_time)
|
130
|
-
|
135
|
+
unless fire_callbacks(:before_run, job, time)
|
136
|
+
logger.info "skipping #{job} due to a `:before_run` callback"
|
137
|
+
return
|
138
|
+
end
|
131
139
|
|
132
140
|
ran = job.run(time, error_handler)
|
133
141
|
|
data/lib/zhong/version.rb
CHANGED
data/lib/zhong/web.rb
CHANGED
@@ -10,19 +10,21 @@ module Zhong
|
|
10
10
|
enable :sessions
|
11
11
|
use ::Rack::Protection, use: :authenticity_token unless ENV["RACK_ENV"] == "test"
|
12
12
|
|
13
|
-
# :nocov:
|
14
13
|
if ENV["ZHONG_WEB_USERNAME"] && ENV["ZHONG_WEB_PASSWORD"]
|
14
|
+
# :nocov:
|
15
15
|
use Rack::Auth::Basic, "Sorry." do |username, password|
|
16
16
|
username == ENV["ZHONG_WEB_USERNAME"] and password == ENV["ZHONG_WEB_PASSWORD"]
|
17
17
|
end
|
18
|
+
# :nocov:
|
18
19
|
end
|
19
20
|
|
20
21
|
if ENV["RACK_ENV"] == "development"
|
22
|
+
# :nocov:
|
21
23
|
before do
|
22
24
|
STDERR.puts "[params] #{params}" unless params.empty?
|
23
25
|
end
|
26
|
+
# :nocov:
|
24
27
|
end
|
25
|
-
# :nocov:
|
26
28
|
|
27
29
|
set :root, File.expand_path(File.dirname(__FILE__) + "/../../web")
|
28
30
|
set :public_folder, proc { "#{root}/assets" }
|
@@ -71,12 +73,12 @@ if defined?(::ActionDispatch::Request::Session) && !::ActionDispatch::Request::S
|
|
71
73
|
# mperham/sidekiq#2460
|
72
74
|
# Rack apps can't reuse the Rails session store without
|
73
75
|
# this monkeypatch
|
74
|
-
# :nocov:
|
75
76
|
class ActionDispatch::Request::Session
|
77
|
+
# :nocov:
|
76
78
|
def each(&block)
|
77
79
|
hash = self.to_hash
|
78
80
|
hash.each(&block)
|
79
81
|
end
|
82
|
+
# :nocov:
|
80
83
|
end
|
81
|
-
# :nocov:
|
82
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zhong
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Elser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: suo
|