procrastinator 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/procrastinator/environment.rb +18 -8
- data/lib/procrastinator/version.rb +1 -1
- data/lib/procrastinator.rb +4 -4
- 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: 085c07da4d7c83dcccb46159c9bad1fc17717013
|
4
|
+
data.tar.gz: aaa2554edfe76056856da018705a21bef6a5345f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27cf0c1198f7c0f7e3c1208ff52f93a1c9fa7117ec2dcd8c7433f334cfeefb4b6e3dd43ed126be7058aeb60b7e78038fc3db138588e5eb267346fd7e43c7a0d6
|
7
|
+
data.tar.gz: cd0a15608dfa630cd70958d1040b06a63e127efca81e08f45642ee4fc427ead3a1ddf0d3f46243752f8a77d265cbcf562ecb2d01b51fed06d97ca1c9159bcfaf
|
@@ -4,14 +4,7 @@ module Procrastinator
|
|
4
4
|
|
5
5
|
DEFAULT_LOG_DIRECTORY = 'log/'
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
raise ArgumentError.new('persister cannot be nil') if persister.nil?
|
9
|
-
|
10
|
-
[:read_tasks, :create_task, :update_task, :delete_task].each do |method|
|
11
|
-
raise MalformedPersisterError.new("persister must repond to ##{method}") unless persister.respond_to? method
|
12
|
-
end
|
13
|
-
|
14
|
-
@persister = persister
|
7
|
+
def initialize(test_mode: false)
|
15
8
|
@test_mode = test_mode
|
16
9
|
@queue_definitions = {}
|
17
10
|
@queue_workers = []
|
@@ -20,6 +13,12 @@ module Procrastinator
|
|
20
13
|
@log_level = Logger::INFO
|
21
14
|
end
|
22
15
|
|
16
|
+
def persister_factory(&block)
|
17
|
+
@persister_factory = block
|
18
|
+
|
19
|
+
build_persister
|
20
|
+
end
|
21
|
+
|
23
22
|
def define_queue(name, properties={})
|
24
23
|
raise ArgumentError.new('queue name cannot be nil') if name.nil?
|
25
24
|
|
@@ -35,6 +34,7 @@ module Procrastinator
|
|
35
34
|
else
|
36
35
|
@queue_definitions.each do |name, props|
|
37
36
|
pid = fork do
|
37
|
+
build_persister
|
38
38
|
worker = QueueWorker.new(props.merge(name: name,
|
39
39
|
persister: @persister,
|
40
40
|
log_dir: @log_dir,
|
@@ -131,6 +131,16 @@ module Procrastinator
|
|
131
131
|
|
132
132
|
heartbeat_thread.abort_on_exception = true
|
133
133
|
end
|
134
|
+
|
135
|
+
def build_persister
|
136
|
+
@persister = @persister_factory.call
|
137
|
+
|
138
|
+
raise ArgumentError.new('persister cannot be nil') if @persister.nil?
|
139
|
+
|
140
|
+
[:read_tasks, :create_task, :update_task, :delete_task].each do |method|
|
141
|
+
raise MalformedPersisterError.new("persister must repond to ##{method}") unless @persister.respond_to? method
|
142
|
+
end
|
143
|
+
end
|
134
144
|
end
|
135
145
|
|
136
146
|
class MalformedPersisterError < StandardError
|
data/lib/procrastinator.rb
CHANGED
@@ -8,15 +8,15 @@ require 'logger'
|
|
8
8
|
module Procrastinator
|
9
9
|
@@test_mode = false
|
10
10
|
|
11
|
-
def self.setup(
|
11
|
+
def self.setup(&block)
|
12
12
|
raise ArgumentError.new('Procrastinator.setup must be given a block') if block.nil?
|
13
13
|
|
14
|
-
env = Environment.new(
|
14
|
+
env = Environment.new(test_mode: @@test_mode)
|
15
15
|
|
16
16
|
yield(env)
|
17
17
|
|
18
|
-
raise RuntimeError.new('setup block
|
19
|
-
|
18
|
+
raise RuntimeError.new('setup block must call #persister_factory on the environment') if env.persister.nil?
|
19
|
+
raise RuntimeError.new('setup block must call #define_queue on the environment') if env.queue_definitions.empty?
|
20
20
|
env.spawn_workers
|
21
21
|
|
22
22
|
env
|