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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ffc8c7bca7bcfddac8f0b86e428920ad3c12554
4
- data.tar.gz: e68d47728ebcedda262ed1c7e3843162a64feb05
3
+ metadata.gz: 085c07da4d7c83dcccb46159c9bad1fc17717013
4
+ data.tar.gz: aaa2554edfe76056856da018705a21bef6a5345f
5
5
  SHA512:
6
- metadata.gz: c74017a1c0d6dab41e5fbd7f7ef8c20fe61b8dc284b1e1ef72a856fed0123f450bca2144d5f8bdeff33b6de60f3b0c8acae677fb43f28236358244dc704bc3f0
7
- data.tar.gz: 1e43eb8665474cfd59c29a12721f25b6ebe4134ead5fa89114d9631cabe227ed6f37a4e318ab6004a0493b615ed9407f402778e619eebc954e80e9bf4b6e9756
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(persister:, test_mode: false)
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
@@ -1,3 +1,3 @@
1
1
  module Procrastinator
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -8,15 +8,15 @@ require 'logger'
8
8
  module Procrastinator
9
9
  @@test_mode = false
10
10
 
11
- def self.setup(persister, &block)
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(persister: persister, test_mode: @@test_mode)
14
+ env = Environment.new(test_mode: @@test_mode)
15
15
 
16
16
  yield(env)
17
17
 
18
- raise RuntimeError.new('setup block did not define any queues') if env.queue_definitions.empty?
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procrastinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Miller