pigeon 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/pigeon/engine.rb +50 -0
- data/lib/pigeon/sorted_array.rb +1 -0
- data/pigeon.gemspec +46 -48
- data/test/unit/pigeon_sorted_array_test.rb +6 -4
- metadata +5 -6
- data/.gitignore +0 -14
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.9
|
data/lib/pigeon/engine.rb
CHANGED
@@ -60,6 +60,29 @@ class Pigeon::Engine
|
|
60
60
|
@name or self.to_s.gsub(/::/, ' ')
|
61
61
|
end
|
62
62
|
|
63
|
+
# Returns the custom process name for this engine or nil if not assigned.
|
64
|
+
def self.process_name
|
65
|
+
@process_name
|
66
|
+
end
|
67
|
+
|
68
|
+
# Assigns the process name. This will be applied only when the engine is
|
69
|
+
# started.
|
70
|
+
def self.process_name=(value)
|
71
|
+
@process_name = value
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns the user this process should run as, or nil if no particular
|
75
|
+
# user is required. This will be applied after the engine has been started
|
76
|
+
# and the after_start call has been triggered.
|
77
|
+
def self.user
|
78
|
+
@user
|
79
|
+
end
|
80
|
+
|
81
|
+
# Assigns the user this process should run as, given a username.
|
82
|
+
def self.user=(value)
|
83
|
+
@user = value
|
84
|
+
end
|
85
|
+
|
63
86
|
# Returns the name of the PID file to use. The full path to the file
|
64
87
|
# is specified elsewhere.
|
65
88
|
def self.pid_file_name
|
@@ -231,6 +254,8 @@ class Pigeon::Engine
|
|
231
254
|
# Handles the run phase of the engine, triggers the before_start and
|
232
255
|
# after_start events accordingly.
|
233
256
|
def run
|
257
|
+
assign_process_name!
|
258
|
+
|
234
259
|
run_chain(:before_start)
|
235
260
|
|
236
261
|
STDOUT.sync = true
|
@@ -238,6 +263,8 @@ class Pigeon::Engine
|
|
238
263
|
logger.info("Engine \##{id} Running")
|
239
264
|
|
240
265
|
run_chain(:after_start)
|
266
|
+
|
267
|
+
switch_to_effective_user! if (self.class.user)
|
241
268
|
end
|
242
269
|
|
243
270
|
# Used to periodically execute a task or block. When giving a task name,
|
@@ -374,4 +401,27 @@ protected
|
|
374
401
|
def run_chain(chain_name)
|
375
402
|
self.class.run_chain(chain_name, self)
|
376
403
|
end
|
404
|
+
|
405
|
+
def switch_to_effective_user!
|
406
|
+
require 'etc'
|
407
|
+
|
408
|
+
requested_user = Etc.getpwnam(self.class.user)
|
409
|
+
requested_uid = (requested_user and requested_user.uid)
|
410
|
+
|
411
|
+
if (Process.uid != requested_uid)
|
412
|
+
switched_to_uid = Process::UID.change_privilege(requested_uid)
|
413
|
+
|
414
|
+
unless (requested_uid == switched_to_uid)
|
415
|
+
STDERR.puts "Could not switch to effective UID #{uid} (#{self.class.user})"
|
416
|
+
exit(-9)
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
def assign_process_name!
|
422
|
+
puts self.class.process_name.inspect
|
423
|
+
if (self.class.process_name)
|
424
|
+
$0 = self.class.process_name
|
425
|
+
end
|
426
|
+
end
|
377
427
|
end
|
data/lib/pigeon/sorted_array.rb
CHANGED
data/pigeon.gemspec
CHANGED
@@ -1,76 +1,74 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pigeon}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["tadman"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-18}
|
13
13
|
s.default_executable = %q{launcher.example}
|
14
14
|
s.description = %q{Pigeon is a simple way to get started building an EventMachine engine that's intended to run as a background job.}
|
15
15
|
s.email = %q{github@tadman.ca}
|
16
16
|
s.executables = ["launcher.example"]
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE",
|
19
|
-
|
19
|
+
"README.rdoc"
|
20
20
|
]
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
"test/unit/pigeon_test.rb"
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"bin/launcher.example",
|
28
|
+
"lib/pigeon.rb",
|
29
|
+
"lib/pigeon/dispatcher.rb",
|
30
|
+
"lib/pigeon/engine.rb",
|
31
|
+
"lib/pigeon/launcher.rb",
|
32
|
+
"lib/pigeon/logger.rb",
|
33
|
+
"lib/pigeon/option_accessor.rb",
|
34
|
+
"lib/pigeon/pidfile.rb",
|
35
|
+
"lib/pigeon/processor.rb",
|
36
|
+
"lib/pigeon/queue.rb",
|
37
|
+
"lib/pigeon/scheduler.rb",
|
38
|
+
"lib/pigeon/sorted_array.rb",
|
39
|
+
"lib/pigeon/support.rb",
|
40
|
+
"lib/pigeon/task.rb",
|
41
|
+
"pigeon.gemspec",
|
42
|
+
"test/helper.rb",
|
43
|
+
"test/unit/pigeon_backlog_test.rb",
|
44
|
+
"test/unit/pigeon_dispatcher_test.rb",
|
45
|
+
"test/unit/pigeon_engine_test.rb",
|
46
|
+
"test/unit/pigeon_launcher_test.rb",
|
47
|
+
"test/unit/pigeon_option_accessor_test.rb",
|
48
|
+
"test/unit/pigeon_processor_test.rb",
|
49
|
+
"test/unit/pigeon_queue_test.rb",
|
50
|
+
"test/unit/pigeon_scheduler_test.rb",
|
51
|
+
"test/unit/pigeon_sorted_array_test.rb",
|
52
|
+
"test/unit/pigeon_task_test.rb",
|
53
|
+
"test/unit/pigeon_test.rb"
|
55
54
|
]
|
56
55
|
s.homepage = %q{http://github.com/twg/pigeon}
|
57
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
58
56
|
s.require_paths = ["lib"]
|
59
57
|
s.rubygems_version = %q{1.3.7}
|
60
58
|
s.summary = %q{Simple daemonized EventMachine engine framework with plug-in support}
|
61
59
|
s.test_files = [
|
62
60
|
"test/helper.rb",
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
61
|
+
"test/unit/pigeon_backlog_test.rb",
|
62
|
+
"test/unit/pigeon_dispatcher_test.rb",
|
63
|
+
"test/unit/pigeon_engine_test.rb",
|
64
|
+
"test/unit/pigeon_launcher_test.rb",
|
65
|
+
"test/unit/pigeon_option_accessor_test.rb",
|
66
|
+
"test/unit/pigeon_processor_test.rb",
|
67
|
+
"test/unit/pigeon_queue_test.rb",
|
68
|
+
"test/unit/pigeon_scheduler_test.rb",
|
69
|
+
"test/unit/pigeon_sorted_array_test.rb",
|
70
|
+
"test/unit/pigeon_task_test.rb",
|
71
|
+
"test/unit/pigeon_test.rb"
|
74
72
|
]
|
75
73
|
|
76
74
|
if s.respond_to? :specification_version then
|
@@ -21,13 +21,15 @@ class PigeonSortedArrayTest < Test::Unit::TestCase
|
|
21
21
|
def test_does_sorting
|
22
22
|
array = Pigeon::SortedArray.new
|
23
23
|
|
24
|
-
test_array =
|
24
|
+
test_array = [2, 2, 2, 2, 3, 3, 3]
|
25
25
|
|
26
|
-
|
26
|
+
test_array.each do |i|
|
27
|
+
array << i
|
28
|
+
end
|
27
29
|
|
28
|
-
assert_equal
|
30
|
+
assert_equal [2, 2, 2, 2, 3, 3, 3], array.to_a
|
29
31
|
end
|
30
|
-
|
32
|
+
|
31
33
|
def test_does_sorting_with_insertion_in_order
|
32
34
|
array = Pigeon::SortedArray.new
|
33
35
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 9
|
9
|
+
version: 0.4.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- tadman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-18 00:00:00 -05:00
|
18
18
|
default_executable: launcher.example
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -41,7 +41,6 @@ extra_rdoc_files:
|
|
41
41
|
- README.rdoc
|
42
42
|
files:
|
43
43
|
- .document
|
44
|
-
- .gitignore
|
45
44
|
- LICENSE
|
46
45
|
- README.rdoc
|
47
46
|
- Rakefile
|
@@ -78,8 +77,8 @@ homepage: http://github.com/twg/pigeon
|
|
78
77
|
licenses: []
|
79
78
|
|
80
79
|
post_install_message:
|
81
|
-
rdoc_options:
|
82
|
-
|
80
|
+
rdoc_options: []
|
81
|
+
|
83
82
|
require_paths:
|
84
83
|
- lib
|
85
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|