senotrusov-ruby-daemonic-threads 1.0.1 → 1.0.2

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.
@@ -23,6 +23,8 @@ class DaemonicThreads::Config
23
23
  @queue_names = get_queue_names
24
24
 
25
25
  @daemons.each do |name, config|
26
+ raise "Class name for daemon `#{name}' must be specified" if config["class"].nil? || config["class"].empty?
27
+
26
28
  config["class-constantized"] = config["class"].constantize
27
29
  end
28
30
 
@@ -39,7 +41,7 @@ class DaemonicThreads::Config
39
41
  @daemons.collect do |name, config|
40
42
  if config["queues"]
41
43
  config["queues"].each do |queue_daemon_handler, queue_name|
42
- names.push queue_name
44
+ names.push queue_name.to_sym
43
45
  end
44
46
  end
45
47
  end
@@ -82,8 +82,8 @@ module DaemonicThreads::HTTP::Daemon
82
82
  REST_METHODS = {"POST" => "create", "PUT" => "update", "DELETE" => "destroy"}
83
83
 
84
84
  def determine_http_action request
85
-
86
- if request.requested_id
85
+
86
+ if request.requested_id
87
87
  if respond_to?(request.requested_id) && !request.requested_action
88
88
  action = request.requested_id
89
89
  else
@@ -182,7 +182,9 @@ class DaemonicThreads::HTTP::HttpRequest
182
182
  attr_reader :requested_format, :requested_id, :requested_action # nil or string
183
183
 
184
184
  def correct?
185
- [Mime::XML, Mime::JSON, nil].include?(requested_format)
185
+ [Mime::XML, Mime::JSON, nil].include?(requested_format) &&
186
+ (@requested_id.nil? || !@requested_id.blank?) &&
187
+ (@requested_action.nil? || !@requested_action.blank?)
186
188
  end
187
189
 
188
190
  def request_method
@@ -344,7 +346,12 @@ class DaemonicThreads::HTTP::HttpRequest
344
346
  @response.start(status_code) do |head, out|
345
347
  head["Location"] = location if location
346
348
  head["Content-Type"] = (options[:content_type] || format).to_s
347
- out.write(data) unless head?
349
+
350
+ unless head?
351
+ Rails.logger.debug { "HTTP RESPONSE:\n#{data}" }
352
+ out.write(data)
353
+ end
354
+
348
355
  end
349
356
  end
350
357
  end
@@ -58,9 +58,15 @@ module DaemonicThreads::Prototype
58
58
  @logger = Rails.logger
59
59
  @parent = parent
60
60
 
61
+ @queues = {}
62
+
61
63
  @config["queues"].each do |queue_handler, queue_name|
62
- instance_variable_set("@#{queue_handler}", @process.queues[queue_name])
64
+ @queues[queue_handler.to_sym] = @process.queues[queue_name.to_sym]
63
65
  end if @config["queues"]
66
+
67
+ @queues.each do |queue_handler, queue|
68
+ instance_variable_set("@#{queue_handler}", queue)
69
+ end
64
70
 
65
71
  @threads = ThreadGroup.new
66
72
  @daemons = []
@@ -95,10 +101,10 @@ module DaemonicThreads::Prototype
95
101
  @daemons.each {|daemon| daemon.stop }
96
102
 
97
103
  @threads.list.each do |thread|
98
- @config["queues"].each do |queue_handler, queue_name|
99
- instance_variable_get("@#{queue_handler}").release_blocked thread
104
+ @queues.each do |queue_handler, queue|
105
+ queue.release_blocked thread
100
106
  end
101
- end if @config["queues"]
107
+ end unless @queues.empty?
102
108
  end
103
109
 
104
110
 
@@ -15,10 +15,10 @@
15
15
 
16
16
 
17
17
  # NOTE:
18
- # It is not a quarantied delivery queues.
19
- # It rely on normal process startup/shutdown sequence.
20
- # So, if you get sigfault all data will be lost.
21
- # On the other hand, queues tends to be quite quickly, since all done in memory
18
+ # This is not a quarantied delivery queues.
19
+ # They rely on normal process startup/shutdown sequence.
20
+ # So, if you got segfault all data will be lost.
21
+ # On the other hand, queues tends to be quite quickly
22
22
 
23
23
  class DaemonicThreads::Queues
24
24
 
@@ -40,12 +40,13 @@ class DaemonicThreads::Queues
40
40
  else
41
41
  @queues[name] = SmartQueue.new
42
42
  end
43
+ @queues[name].persistent = true
43
44
  end
44
45
  end
45
46
 
46
47
  def store
47
48
  @queues.each do |name, queue|
48
- File.write("#{@storage_dir}/#{name}", queue.to_storage)
49
+ File.write("#{@storage_dir}/#{name}", queue.to_storage) if queue.persistent
49
50
  end
50
51
  end
51
52
 
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.1
4
+ version: 1.0.2
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-07-23 00:00:00 -07:00
12
+ date: 2009-07-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -81,6 +81,7 @@ files:
81
81
  - lib/ruby-daemonic-threads.rb
82
82
  has_rdoc: false
83
83
  homepage: http://github.com/senotrusov
84
+ licenses:
84
85
  post_install_message:
85
86
  rdoc_options:
86
87
  - --inline-source
@@ -102,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  requirements: []
103
104
 
104
105
  rubyforge_project:
105
- rubygems_version: 1.2.0
106
+ rubygems_version: 1.3.5
106
107
  signing_key:
107
108
  specification_version: 3
108
109
  summary: Create multithreaded applications with smart persistent internal queues, WEB/REST interface, exception handling and recovery