zhong 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8e24ce8cbfc3ebd6b0574c791aef211bb0777c1
4
- data.tar.gz: cd327270c61bbfb6817096ff5e2f2aee1ade850e
3
+ metadata.gz: 6786d80a0d2da5fc3d4605ab95a511764b96e2e6
4
+ data.tar.gz: 2c1f61feff58195e3e8521b7d965f0cb7ed0d616
5
5
  SHA512:
6
- metadata.gz: b5955bed476e79f2b79520523724320404733986912bda9d3d6fc1396c578a935336fd2927295579f9bfe838baf2ee4d55ff953ab6a0f5f4332d3afb85ad0678
7
- data.tar.gz: e8082120c278422e3d1f04660739877d4d7fba6573745c31f63df0df4116d719a424087e1d3b8ac06d863d1dd0c98ebfd3489a7e411dcebe08228a1c6fc07ec4
6
+ metadata.gz: 3e9b281a5edbd9a6aa9c99ecff01b24f153c886ea2bf91d4659cf92ef858da518e5d96f18ce9b7e253372dc07e8749289fddff77104e72cd61df056fa72d9028
7
+ data.tar.gz: e0c854e2d554048f88fa4368701c2d59e7e40dccb2d2165f43df3d9ffd679c382c485b1b2f566617a1de0dd17657aef9f2ed07d9f93bb394f6e3abcf9dbdcf85
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.1.8
2
+
3
+ - Make it very clear when callbacks cause skips of ticks or runs.
4
+ - Add logging when jobs/ticks are skipped.
5
+ - Do not skip when callbacks return nil (only on false explicitly).
6
+
1
7
  ## 0.1.7
2
8
 
3
9
  - Improve test coverage.
data/README.md CHANGED
@@ -34,7 +34,7 @@ Zhong.schedule do
34
34
  end
35
35
  end
36
36
 
37
- # note: callbacks that return nil or false will cause event to not run
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|
@@ -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
- @logger.info "starting at #{redis_time}"
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
- sleep_until_next_second
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 { @logger.info "stopped" }.join
101
+ Thread.new { logger.info "stopped" }.join
99
102
  end
100
103
 
101
104
  def stop
102
- Thread.new { @logger.error "stopping" } if @running # thread necessary due to trap context
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.all? { |h| h.call(*args) }
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
- return unless fire_callbacks(:before_run, job, time)
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
@@ -1,3 +1,3 @@
1
1
  module Zhong
2
- VERSION = "0.1.7".freeze
2
+ VERSION = "0.1.8".freeze
3
3
  end
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.7
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-01 00:00:00.000000000 Z
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: suo