senotrusov-ruby-daemonic-threads 1.0.7 → 1.0.9

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.
@@ -20,28 +20,42 @@ class DaemonicThreads::Config
20
20
  config["environment"] && !(config["environment"].split(/ *, */).include?(Rails.env))
21
21
  end
22
22
 
23
- @queue_names = get_queue_names
23
+ @queues = @daemons.delete("queues") || {}
24
+
25
+ daemons_use_queues.each do |name|
26
+ @queues[name] ||= {}
27
+ end
28
+
29
+ @queues.each do |name, config|
30
+ config = @queues[name] = {} unless config
31
+
32
+ if config["class"].nil? || config["class"].empty?
33
+ config["class-constantized"] = PersistentQueue
34
+ else
35
+ config["class-constantized"] = config["class"].constantize
36
+ end
37
+ end
24
38
 
25
39
  @daemons.each do |name, config|
26
40
  raise "Class name for daemon `#{name}' must be specified" if config["class"].nil? || config["class"].empty?
27
41
 
28
42
  config["class-constantized"] = config["class"].constantize
29
- end
43
+ end
30
44
 
31
45
  Rails.logger.debug {"#{self.class}#initialize -- Configuration: #{self.inspect}"}
32
46
  end
33
47
 
34
- attr_reader :queue_names, :daemons
48
+ attr_reader :queues, :daemons
35
49
 
36
50
  private
37
51
 
38
- def get_queue_names
52
+ def daemons_use_queues
39
53
  names = []
40
54
 
41
55
  @daemons.collect do |name, config|
42
56
  if config["queues"]
43
57
  config["queues"].each do |queue_daemon_handler, queue_name|
44
- names.push queue_name.to_sym
58
+ names.push queue_name
45
59
  end
46
60
  end
47
61
  end
@@ -29,8 +29,6 @@ class DaemonicThreads::Process
29
29
  attr_reader :controller, :name, :config, :http, :queues, :daemons
30
30
 
31
31
  def start
32
- @queues.restore
33
-
34
32
  @http.start
35
33
  @daemons.start
36
34
  end
@@ -46,7 +44,7 @@ class DaemonicThreads::Process
46
44
  end
47
45
 
48
46
  def before_exit
49
- @queues.store
47
+ @queues.store_and_close
50
48
  end
51
49
 
52
50
  end
@@ -21,53 +21,40 @@
21
21
  # On the other hand, queues tends to be quite quickly
22
22
 
23
23
  class DaemonicThreads::Queues
24
-
25
24
  DEFAULT_STORAGE_DIR = Rails.root + 'tmp' + 'queues'
26
25
 
27
26
  def initialize(process)
28
27
  @queues = {}
28
+ @config = process.config.queues
29
+
29
30
  @storage_dir = DEFAULT_STORAGE_DIR
30
- @queue_names = process.config.queue_names
31
+ @storage_dir.mkpath
31
32
 
32
- raise("Queues storage directory #{@storage_dir} is not available!") unless storage_available?
33
- end
34
-
35
- def restore
36
- @queue_names.each do |name|
37
- if File.exists?(filename = "#{@storage_dir}/#{name}")
38
- @queues[name] = SmartQueue.new(File.read(filename))
39
- File.unlink(filename)
40
- else
41
- @queues[name] = SmartQueue.new
33
+ @config.each do |name, config|
34
+
35
+ queue = @queues[name.to_sym] = config["class-constantized"].new
36
+
37
+ if queue.respond_to?(:restore)
38
+ queue.storage = @storage_dir + name
39
+ queue.restore
40
+ end
41
+
42
+ if queue.respond_to?(:config=)
43
+ queue.config = config
42
44
  end
43
- @queues[name].persistent = true
45
+
44
46
  end
47
+
45
48
  end
46
49
 
47
- def store
50
+ def store_and_close
48
51
  @queues.each do |name, queue|
49
- File.write("#{@storage_dir}/#{name}", queue.to_storage) if queue.persistent
52
+ queue.store_and_close if queue.respond_to?(:store_and_close)
50
53
  end
51
54
  end
52
55
 
53
56
  def [] name
54
57
  @queues[name]
55
58
  end
56
-
57
- private
58
-
59
- def storage_available?
60
- if File.directory?(@storage_dir) && File.writable?(@storage_dir)
61
- return true
62
- else
63
- begin
64
- Dir.mkdir(@storage_dir)
65
- return true
66
- rescue SystemCallError
67
- return false
68
- end
69
- end
70
- end
71
-
72
59
  end
73
60
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: senotrusov-ruby-daemonic-threads
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav Senotrusov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-06 00:00:00 -07:00
12
+ date: 2009-08-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency