gaspar 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ gem 'colorize'
7
7
  gem 'rspec'
8
8
  gem 'redis'
9
9
  gem 'active_support'
10
- gem 'timecop'
10
+ gem 'timecop'
11
+ gem 'rake'
data/Rakefile CHANGED
@@ -1,3 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rspec/core/rake_task'
3
- RSpec::Core::RakeTask.new('spec')
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |spec|
5
+ spec.pattern = 'spec/**/*_spec.rb'
6
+ spec.rspec_opts = ['--color --format documentation']
7
+ end
8
+ task :default => :spec
data/lib/gaspar.rb CHANGED
@@ -54,6 +54,10 @@ class Gaspar
54
54
  end
55
55
  end
56
56
 
57
+ def can_run_if(&block)
58
+ @can_run_if = block
59
+ end
60
+
57
61
  def before_each(&block)
58
62
  self.class.set_callback :run, :before, &block
59
63
  end
@@ -100,6 +104,13 @@ class Gaspar
100
104
  @lock.synchronize { yield }
101
105
  end
102
106
 
107
+ def can_run?
108
+ return false if STDOUT.tty? or STDERR.tty?
109
+ return false if @can_run_if and @can_run_if.call == false
110
+ return false if Object.const_defined? :Rails and Rails.env.test? and !@options[:permit_test_mode]
111
+ return true
112
+ end
113
+
103
114
  def schedule(method, timing, args = [], options = {}, &block)
104
115
  if block_given?
105
116
  options[:name] ||= args.first
@@ -159,10 +170,7 @@ class Gaspar
159
170
  end
160
171
 
161
172
  def start!(redis)
162
- return log "Running under a controlling TTY. Refusing to start. Try starting from a daemonized process." if STDOUT.tty? or STDERR.tty?
163
- if Object.const_defined? :Rails and Rails.env.test?
164
- return unless @options[:permit_test_mode]
165
- end
173
+ return log "Running under a controlling TTY. Refusing to start. Try starting from a daemonized process." unless can_run?
166
174
 
167
175
  @redis = redis
168
176
 
@@ -1,3 +1,3 @@
1
1
  class Gaspar
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -11,6 +11,13 @@ describe Gaspar do
11
11
  every "5m", :Foo
12
12
  end.start!(redis)
13
13
  end
14
+
15
+ it "should refuse to start if #can_start_if is present and returns false" do
16
+ Gaspar.configure do
17
+ can_run_if { false }
18
+ every "5m", :Foo
19
+ end.start!(redis)
20
+ end
14
21
  end
15
22
 
16
23
  context "when running in a daemon" do
@@ -180,7 +187,7 @@ describe Gaspar do
180
187
  Time.stub!(:now).and_return(150)
181
188
  redis = double :redis, :setnx => false, :get => "100", :ttl => (3.2e8.to_i - 25)
182
189
  instance = Gaspar.send(:new)
183
- instance.instance_variable_set(:@redis, redis)
190
+ instance.instance_variable_set(:@redis, redis)
184
191
  instance.send :sync_watches
185
192
  instance.drift.should == 25
186
193
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaspar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,104 +9,104 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-12 00:00:00.000000000 Z
12
+ date: 2013-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rufus-scheduler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
20
+ none: false
22
21
  type: :runtime
23
- prerelease: false
22
+ name: rufus-scheduler
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
25
  - - ! '>='
28
26
  - !ruby/object:Gem::Version
29
27
  version: '0'
28
+ none: false
29
+ prerelease: false
30
30
  - !ruby/object:Gem::Dependency
31
- name: redis
32
31
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
32
  requirements:
35
33
  - - ! '>='
36
34
  - !ruby/object:Gem::Version
37
35
  version: 2.2.0
36
+ none: false
38
37
  type: :runtime
39
- prerelease: false
38
+ name: redis
40
39
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
40
  requirements:
43
41
  - - ! '>='
44
42
  - !ruby/object:Gem::Version
45
43
  version: 2.2.0
44
+ none: false
45
+ prerelease: false
46
46
  - !ruby/object:Gem::Dependency
47
- name: colorize
48
47
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
48
  requirements:
51
49
  - - ! '>='
52
50
  - !ruby/object:Gem::Version
53
51
  version: '0'
52
+ none: false
54
53
  type: :runtime
55
- prerelease: false
54
+ name: colorize
56
55
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
56
  requirements:
59
57
  - - ! '>='
60
58
  - !ruby/object:Gem::Version
61
59
  version: '0'
60
+ none: false
61
+ prerelease: false
62
62
  - !ruby/object:Gem::Dependency
63
- name: activesupport
64
63
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
64
  requirements:
67
65
  - - ! '>='
68
66
  - !ruby/object:Gem::Version
69
67
  version: '0'
68
+ none: false
70
69
  type: :runtime
71
- prerelease: false
70
+ name: activesupport
72
71
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
72
  requirements:
75
73
  - - ! '>='
76
74
  - !ruby/object:Gem::Version
77
75
  version: '0'
76
+ none: false
77
+ prerelease: false
78
78
  - !ruby/object:Gem::Dependency
79
- name: rspec
80
79
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
80
  requirements:
83
81
  - - ! '>='
84
82
  - !ruby/object:Gem::Version
85
83
  version: '0'
84
+ none: false
86
85
  type: :development
87
- prerelease: false
86
+ name: rspec
88
87
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
88
  requirements:
91
89
  - - ! '>='
92
90
  - !ruby/object:Gem::Version
93
91
  version: '0'
92
+ none: false
93
+ prerelease: false
94
94
  - !ruby/object:Gem::Dependency
95
- name: timecop
96
95
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
96
  requirements:
99
97
  - - ! '>='
100
98
  - !ruby/object:Gem::Version
101
99
  version: '0'
100
+ none: false
102
101
  type: :development
103
- prerelease: false
102
+ name: timecop
104
103
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
104
  requirements:
107
105
  - - ! '>='
108
106
  - !ruby/object:Gem::Version
109
107
  version: '0'
108
+ none: false
109
+ prerelease: false
110
110
  description: Gaspar is an in-process recurring job manager. It is intended to be used
111
111
  in place of cron when you don't want a separate daemon.
112
112
  email:
@@ -132,17 +132,23 @@ rdoc_options: []
132
132
  require_paths:
133
133
  - lib
134
134
  required_ruby_version: !ruby/object:Gem::Requirement
135
- none: false
136
135
  requirements:
137
136
  - - ! '>='
138
137
  - !ruby/object:Gem::Version
138
+ hash: -546882929324832144
139
139
  version: '0'
140
- required_rubygems_version: !ruby/object:Gem::Requirement
140
+ segments:
141
+ - 0
141
142
  none: false
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
144
  requirements:
143
145
  - - ! '>='
144
146
  - !ruby/object:Gem::Version
147
+ hash: -546882929324832144
145
148
  version: '0'
149
+ segments:
150
+ - 0
151
+ none: false
146
152
  requirements: []
147
153
  rubyforge_project:
148
154
  rubygems_version: 1.8.24
@@ -152,4 +158,3 @@ summary: Gaspar is an in-process recurring job manager.
152
158
  test_files:
153
159
  - spec/gaspar/gaspar_spec.rb
154
160
  - spec/spec_helper.rb
155
- has_rdoc: