simultaneous 0.3.3 → 0.4.0

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.
data/Gemfile CHANGED
@@ -2,5 +2,4 @@ source :rubygems
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rack-async', :git => "git://github.com/matsadler/rack-async.git"
6
- # gem 'thin'
5
+ #gem 'rack-async', :git => "git://github.com/matsadler/rack-async.git"
data/lib/simultaneous.rb CHANGED
@@ -4,7 +4,7 @@ require 'socket'
4
4
  require 'eventmachine'
5
5
 
6
6
  module Simultaneous
7
- VERSION = "0.3.3"
7
+ VERSION = "0.4.0"
8
8
 
9
9
  DEFAULT_CONNECTION = "/tmp/simultaneous-server.sock"
10
10
  DEFAULT_PORT = 9999
@@ -77,10 +77,10 @@ module Simultaneous
77
77
  @client ||= \
78
78
  begin
79
79
  client = \
80
- if ::EM.reactor_running?
81
- Client.new(domain, connection)
80
+ if client_mode == :async and ::EM.reactor_running?
81
+ AsyncClient.new(domain, connection)
82
82
  else
83
- TaskClient.new(domain, connection)
83
+ SyncClient.new(domain, connection)
84
84
  end
85
85
  # make sure that new client is hooked into all listeners
86
86
  event_listeners.each do |event, blocks|
@@ -139,6 +139,10 @@ module Simultaneous
139
139
  @domain = domain
140
140
  end
141
141
 
142
+ def client_mode=(mode)
143
+ @client_mode = mode
144
+ end
145
+
142
146
  def connection
143
147
  @connection ||= (ENV[Simultaneous::ENV_CONNECTION] || Simultaneous::DEFAULT_CONNECTION)
144
148
  end
@@ -147,6 +151,11 @@ module Simultaneous
147
151
  @domain ||= (ENV[Simultaneous::ENV_DOMAIN] || "domain#{$$}")
148
152
  end
149
153
 
154
+ def client_mode
155
+ reset_client!
156
+ @client_mode ||= :async
157
+ end
158
+
150
159
  # Used by the {Simultaneous::Daemon} module to set the correct PID for a given task
151
160
  def map_pid(task_name, pid)
152
161
  command = Command::SetPid.new(task_name, pid)
@@ -255,8 +264,8 @@ module Simultaneous
255
264
 
256
265
  autoload :Connection, "simultaneous/connection"
257
266
  autoload :Server, "simultaneous/server"
258
- autoload :Client, "simultaneous/client"
259
- autoload :TaskClient, "simultaneous/task_client"
267
+ autoload :AsyncClient, "simultaneous/async_client"
268
+ autoload :SyncClient, "simultaneous/sync_client"
260
269
  autoload :Task, "simultaneous/task"
261
270
  autoload :TaskDescription, "simultaneous/task_description"
262
271
  autoload :BroadcastMessage, "simultaneous/broadcast_message"
@@ -3,7 +3,7 @@
3
3
  require 'eventmachine'
4
4
 
5
5
  module Simultaneous
6
- class Client
6
+ class AsyncClient
7
7
 
8
8
 
9
9
  attr_reader :domain
@@ -32,7 +32,7 @@ module Simultaneous
32
32
  end
33
33
 
34
34
  # def unbind
35
- # $stdout.puts "Client Connection closed\\n"
35
+ # $stdout.puts "Client Connection closed\\\\\\\\n"
36
36
  # client.reconnect!
37
37
  # end
38
38
  end
@@ -63,6 +63,7 @@ module Simultaneous
63
63
  Process::GID.change_privilege(task_gid) unless Process.egid == task_gid
64
64
  Process::UID.change_privilege(task_uid) unless Process.euid == task_uid
65
65
  File.umask(0022)
66
+ redirect_io(@task.logfile)
66
67
  Dir.chdir(@task.pwd)
67
68
  exec(cmd)
68
69
  end
@@ -110,8 +111,6 @@ module Simultaneous
110
111
  end
111
112
  end
112
113
 
113
- redirect_io(logfile_name)
114
-
115
114
  return sess_id
116
115
  end
117
116
 
@@ -73,7 +73,7 @@ module Simultaneous
73
73
 
74
74
  def set_socket_permissions(socket)
75
75
  if File.exist?(socket)
76
- File.chmod(0777, socket)
76
+ File.chmod(00777, socket)
77
77
  File.chown(nil, options[:gid], socket) if options[:gid]
78
78
  end
79
79
  end
@@ -58,7 +58,9 @@ module Simultaneous
58
58
 
59
59
  @lock.synchronize { @clients << stream }
60
60
 
61
- [200, {"Content-type" => "text/event-stream"}, stream]
61
+ # Nginx specific header to disable buffering
62
+ # see: http://wiki.nginx.org/X-accel#X-Accel-Buffering
63
+ [200, {"Content-type" => "text/event-stream", "X-Accel-Buffering" => "no"}, stream]
62
64
  end
63
65
 
64
66
  def deliver_event(event)
@@ -3,7 +3,7 @@
3
3
  require 'socket'
4
4
 
5
5
  module Simultaneous
6
- class TaskClient
6
+ class SyncClient
7
7
  attr_reader :domain
8
8
 
9
9
  def initialize(domain = Simultaneous.domain, connection_string=Simultaneous.connection)
data/simultaneous.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'simultaneous'
16
- s.version = '0.3.3'
17
- s.date = '2012-02-21'
16
+ s.version = '0.4.0'
17
+ s.date = '2012-02-23'
18
18
  s.rubyforge_project = 'simultaneous'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -63,8 +63,8 @@ Gem::Specification.new do |s|
63
63
  bin/simultaneous-console
64
64
  bin/simultaneous-server
65
65
  lib/simultaneous.rb
66
+ lib/simultaneous/async_client.rb
66
67
  lib/simultaneous/broadcast_message.rb
67
- lib/simultaneous/client.rb
68
68
  lib/simultaneous/command.rb
69
69
  lib/simultaneous/command/client_event.rb
70
70
  lib/simultaneous/command/fire.rb
@@ -74,8 +74,8 @@ Gem::Specification.new do |s|
74
74
  lib/simultaneous/connection.rb
75
75
  lib/simultaneous/rack.rb
76
76
  lib/simultaneous/server.rb
77
+ lib/simultaneous/sync_client.rb
77
78
  lib/simultaneous/task.rb
78
- lib/simultaneous/task_client.rb
79
79
  lib/simultaneous/task_description.rb
80
80
  simultaneous.gemspec
81
81
  test/helper.rb
data/test/helper.rb CHANGED
@@ -1,8 +1,11 @@
1
+ path = File.expand_path('../../lib', __FILE__)
2
+ $:.unshift(path) if File.directory?(path) && !$:.include?(path)
3
+
1
4
  require 'minitest/spec'
2
5
  require 'minitest/autorun'
3
6
  require 'rr'
4
- require 'simultaneous'
5
7
  require 'fileutils'
8
+ require File.expand_path('../../lib/simultaneous', __FILE__)
6
9
 
7
10
 
8
11
  $debug = false
data/test/test_client.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../helper', __FILE__)
2
2
 
3
- describe Simultaneous::Client do
3
+ describe Simultaneous::AsyncClient do
4
4
  it "should send right command to server" do
5
5
  EM.run {
6
6
  task = Simultaneous.add_task(:publish, "/publish", {:param1 => "value1", :param2 => "value2"}, 12)
@@ -79,7 +79,7 @@ describe Simultaneous::Connection do
79
79
  socket = "/tmp/socket.sock"
80
80
  gid = "789"
81
81
  FileUtils.rm(socket) if File.exist?(socket)
82
- mock(File).chmod(0777, socket)
82
+ mock(File).chmod(00777, socket)
83
83
  mock(File).chown(nil, gid, socket)
84
84
  handler = Module.new
85
85
  mock(EventMachine).start_server(socket, handler) { FileUtils.touch(socket) }
data/test/test_server.rb CHANGED
@@ -18,9 +18,9 @@ describe Simultaneous::Server do
18
18
  EM.run {
19
19
  Simultaneous::Server.start(SOCKET)
20
20
 
21
- client1 = Simultaneous::Client.new("domain1", SOCKET)
22
- client2 = Simultaneous::Client.new("domain1", SOCKET)
23
- client3 = Simultaneous::Client.new("domain2", SOCKET)
21
+ client1 = Simultaneous::AsyncClient.new("domain1", SOCKET)
22
+ client2 = Simultaneous::AsyncClient.new("domain1", SOCKET)
23
+ client3 = Simultaneous::AsyncClient.new("domain2", SOCKET)
24
24
 
25
25
  command = Simultaneous::Command::ClientEvent.new("domain1", "a", "data")
26
26
 
@@ -161,11 +161,11 @@ describe Simultaneous::Server do
161
161
  ENV[Simultaneous::ENV_TASK_NAME] = "publish"
162
162
  ENV[Simultaneous::ENV_CONNECTION] = SOCKET
163
163
 
164
- c = Simultaneous::TaskClient.new("example2.com", SOCKET)
165
- mock(Simultaneous::TaskClient).new { c }
164
+ c = Simultaneous::SyncClient.new("example2.com", SOCKET)
165
+ mock(Simultaneous::SyncClient).new { c }
166
166
  mock(c).run(is_a(Simultaneous::Command::SetPid))
167
167
  proxy(c).run(is_a(Simultaneous::Command::ClientEvent))
168
- client = Simultaneous::Client.new("example2.com", SOCKET)
168
+ client = Simultaneous::AsyncClient.new("example2.com", SOCKET)
169
169
 
170
170
  client.on_event("publish_status") { |event|
171
171
  event.data.must_equal "completed"
@@ -199,8 +199,8 @@ describe Simultaneous::Server do
199
199
  ENV[Simultaneous::ENV_TASK_NAME] = "publish"
200
200
  ENV[Simultaneous::ENV_CONNECTION] = SOCKET
201
201
 
202
- c = Simultaneous::TaskClient.new("example3.com", SOCKET)
203
- mock(Simultaneous::TaskClient).new { c }
202
+ c = Simultaneous::SyncClient.new("example3.com", SOCKET)
203
+ mock(Simultaneous::SyncClient).new { c }
204
204
  mock(c).run(is_a(Simultaneous::Command::SetPid))
205
205
  proxy(c).run(is_a(Simultaneous::Command::Kill))
206
206
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simultaneous
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-21 00:00:00.000000000Z
12
+ date: 2012-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &70282715898340 !ruby/object:Gem::Requirement
16
+ requirement: &70178587096280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: '2.0'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70282715898340
27
+ version_requirements: *70178587096280
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rack
30
- requirement: &70282715897160 !ruby/object:Gem::Requirement
30
+ requirement: &70178587092600 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -38,10 +38,10 @@ dependencies:
38
38
  version: '2.0'
39
39
  type: :runtime
40
40
  prerelease: false
41
- version_requirements: *70282715897160
41
+ version_requirements: *70178587092600
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rack-async
44
- requirement: &70282715896280 !ruby/object:Gem::Requirement
44
+ requirement: &70178587106180 !ruby/object:Gem::Requirement
45
45
  none: false
46
46
  requirements:
47
47
  - - ! '>='
@@ -52,10 +52,10 @@ dependencies:
52
52
  version: '2.0'
53
53
  type: :runtime
54
54
  prerelease: false
55
- version_requirements: *70282715896280
55
+ version_requirements: *70178587106180
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rr
58
- requirement: &70282715895540 !ruby/object:Gem::Requirement
58
+ requirement: &70178587104560 !ruby/object:Gem::Requirement
59
59
  none: false
60
60
  requirements:
61
61
  - - ~>
@@ -63,7 +63,7 @@ dependencies:
63
63
  version: 1.0.4
64
64
  type: :development
65
65
  prerelease: false
66
- version_requirements: *70282715895540
66
+ version_requirements: *70178587104560
67
67
  description: Simultaneous is designed for the very specific use case of a small set
68
68
  of users collaborating on editing a single website. Because of that it is optimised
69
69
  for infrequent invocation of very long running publishing tasks and provides an
@@ -86,8 +86,8 @@ files:
86
86
  - bin/simultaneous-console
87
87
  - bin/simultaneous-server
88
88
  - lib/simultaneous.rb
89
+ - lib/simultaneous/async_client.rb
89
90
  - lib/simultaneous/broadcast_message.rb
90
- - lib/simultaneous/client.rb
91
91
  - lib/simultaneous/command.rb
92
92
  - lib/simultaneous/command/client_event.rb
93
93
  - lib/simultaneous/command/fire.rb
@@ -97,8 +97,8 @@ files:
97
97
  - lib/simultaneous/connection.rb
98
98
  - lib/simultaneous/rack.rb
99
99
  - lib/simultaneous/server.rb
100
+ - lib/simultaneous/sync_client.rb
100
101
  - lib/simultaneous/task.rb
101
- - lib/simultaneous/task_client.rb
102
102
  - lib/simultaneous/task_description.rb
103
103
  - simultaneous.gemspec
104
104
  - test/helper.rb
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  requirements: []
133
133
  rubyforge_project: simultaneous
134
- rubygems_version: 1.8.10
134
+ rubygems_version: 1.8.16
135
135
  signing_key:
136
136
  specification_version: 2
137
137
  summary: Simultaneous is the background task launcher used by Spontaneous CMS