raemon 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,17 +2,70 @@ Raemon
2
2
  ======
3
3
 
4
4
  Raemon is a Ruby framework for building daemons. It's designed for writing
5
- master/worker pre-forking servers running on UNIX. More to come.
5
+ master/worker pre-forking servers running on UNIX. The library has been
6
+ tested on both 1.8.7 and 1.9.1 and carries no dependencies outside of the
7
+ Ruby core. More to come.
6
8
 
7
-
8
- Credits
9
- -------
10
9
  By: Peter Kieltyka
11
10
  Copyright (c) 2007-2009 NuLayer Inc. All rights reserved.
12
11
 
13
12
 
13
+ Usage
14
+ =====
15
+
16
+ Raemon supports two modes of use: as a lightweight master/worker library
17
+ or as a full daemon server.
18
+
19
+
20
+ Lightweight master/worker library
21
+ ---------------------------------
22
+ Simply mixin the Raemon::Worker module into any class and implement the
23
+ 'start' and 'execute' methods.
24
+
25
+ start - called when the worker process is first created
26
+ execute - called to begin the execution of the worker
27
+
28
+ The Raemon::Worker module also provides a 'shutting_down?' helper method
29
+ that should be tested between iterations in the worker loop to gracefully
30
+ shutdown the worker.
31
+
32
+ To start the workers use the Raemon::Master class.
33
+
34
+ See examples/test.rb and examples/beanstalk.rb for how the library works
35
+ in this scenario.
36
+
37
+ Also, you can find an evented Beanstalk example in examples/evented.rb.
38
+
39
+
40
+ Daemon server
41
+ -------------
42
+ Raemon::Server provides tools that helps build daemon applications
43
+ that feel like a Ruby on Rails application. See examples/sampled.
44
+
45
+
46
+ Installation
47
+ ============
48
+ Via gemcutter:
49
+ $ gem install raemon
50
+
51
+ From source:
52
+ $ git clone git://github.com/pkieltyka/raemon.git
53
+ $ cd raemon && rake build
54
+ $ gem install pkg/raemon-X.X.X.gem
55
+
56
+
57
+ TODO
58
+ ====
59
+ 1. Test cases
60
+ 2. Create a UNIX socket connection between the master and workers
61
+ 3. Setup a heartbeat between the master and the workers
62
+ 4. Monitor memory usage of the workers in the master and restart/stop
63
+ a worker if its out of whack
64
+ 5. Write a daemon generator (as examples/sampled)
65
+
66
+
14
67
  Thanks
15
- ------
68
+ ======
16
69
  Raemon was influenced by the following projects:
17
70
 
18
71
  servolux - http://github.com/TwP/servolux
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
  require 'raemon'
5
5
  require 'beanstalk-client'
6
6
 
7
- class Test
7
+ class JobWorker
8
8
  include Raemon::Worker
9
9
 
10
10
  def start
@@ -40,12 +40,12 @@ class Test
40
40
 
41
41
  end
42
42
 
43
- ROOT_DIR = '/Users/peter/Desktop'
43
+ ROOT_DIR = File.expand_path('~')
44
44
 
45
- # Raemon::Master.startup 3, Test, {
45
+ # Raemon::Master.startup 3, JobWorker, {
46
46
  # :detach => true,
47
47
  # :logger => Logger.new("#{ROOT_DIR}/beanstalk.log"),
48
48
  # :pid_file => "#{ROOT_DIR}/beanstalk.pid"
49
49
  # }
50
50
 
51
- Raemon::Master.startup 3, Test
51
+ Raemon::Master.startup 3, JobWorker
@@ -0,0 +1,47 @@
1
+ $:.unshift ::File.dirname(__FILE__) + '/../lib'
2
+
3
+ require 'rubygems'
4
+ require 'raemon'
5
+ require 'em-jack'
6
+
7
+ class EventedJobWorker
8
+ include Raemon::Worker
9
+
10
+ def start
11
+ logger.info "=> Starting worker #{Process.pid}"
12
+ end
13
+
14
+ def stop
15
+ logger.info "=> Stopping worker #{Process.pid}"
16
+
17
+ EM.stop_event_loop if EM.reactor_running?
18
+ exit
19
+ end
20
+
21
+ def execute
22
+ EventMachine.run do
23
+ @queue = EMJack::Connection.new
24
+
25
+ @queue.each_job(5) do |job|
26
+ logger.info "(#{Process.ppid}:#{Process.pid}) got job: #{job.inspect}"
27
+ # process(job)
28
+ @queue.delete(job)
29
+
30
+ stop if shutting_down?
31
+ end
32
+
33
+ @queue.on_error do |error|
34
+ case error
35
+ when :timed_out
36
+ # We use the reserve timeout to check if we should shutdown
37
+ stop if shutting_down?
38
+ else
39
+ logger.error error.to_s
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ Raemon::Master.startup 2, EventedJobWorker
@@ -1,12 +1,10 @@
1
1
  # Be sure to restart your daemon when you modify this file
2
2
 
3
3
  # Uncomment below to force your daemon into production mode
4
- #ENV['DAEMON_ENV'] ||= 'production'
4
+ #ENV['RAEMON_ENV'] ||= 'production'
5
5
 
6
6
  require File.join(File.dirname(__FILE__), 'boot')
7
7
 
8
- require 'ruby-debug'
9
-
10
8
  Raemon::Server.run do |config|
11
9
  config.name = 'Sampled'
12
10
  config.worker_klass = 'Sampled::Worker'
@@ -1,5 +1,5 @@
1
1
  config.detach = false
2
- config.num_workers = 2
2
+ config.num_workers = 1
3
3
  config.log_level = :debug
4
4
 
5
5
  require 'ruby-debug'
@@ -1 +1,3 @@
1
- config.log_level = :debug
1
+ config.detach = false
2
+ config.num_workers = 1
3
+ config.log_level = :debug
File without changes
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class ExampleTest < Test::Unit::TestCase
4
+
5
+ def test_nothing
6
+ assert true
7
+
8
+ assert defined? Sampled::Worker
9
+ end
10
+
11
+ end
@@ -0,0 +1,7 @@
1
+ ENV['RAEMON_ENV'] = 'test'
2
+
3
+ # Add any libs you need for your test suite here
4
+ require 'rubygems'
5
+
6
+ require File.dirname(__FILE__) + '/../config/environment'
7
+ Raemon::Server.startup!
File without changes
File without changes
data/examples/test.rb CHANGED
@@ -26,6 +26,4 @@ class Test
26
26
 
27
27
  end
28
28
 
29
- ROOT_DIR = '/Users/peter/Desktop'
30
-
31
29
  Raemon::Master.startup 3, Test
data/lib/raemon/master.rb CHANGED
@@ -74,7 +74,5 @@ module Raemon
74
74
  trap('TERM', shutdown_block)
75
75
  end
76
76
 
77
- def debugging?; @debug; end
78
-
79
77
  end
80
78
  end
data/lib/raemon/server.rb CHANGED
@@ -59,11 +59,13 @@ module Raemon
59
59
  end
60
60
 
61
61
  def load_initializers
62
- load_folder("#{RAEMON_ROOT}/config/initializers")
62
+ load_folder "#{RAEMON_ROOT}/config/initializers"
63
63
  end
64
64
 
65
65
  def load_lib
66
- load_folder("#{RAEMON_ROOT}/lib")
66
+ libdir = "#{RAEMON_ROOT}/lib"
67
+ $LOAD_PATH.unshift libdir
68
+ load_folder libdir
67
69
  end
68
70
 
69
71
  def load_folder(path)
data/lib/raemon.rb CHANGED
@@ -2,7 +2,7 @@ require 'socket'
2
2
  require 'logger'
3
3
 
4
4
  module Raemon
5
- VERSION = '0.1'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
 
8
8
  require 'raemon/server'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Kieltyka
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-26 00:00:00 -05:00
12
+ date: 2009-11-27 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -29,6 +29,7 @@ files:
29
29
  - Rakefile
30
30
  - VERSION
31
31
  - examples/beanstalk.rb
32
+ - examples/evented.rb
32
33
  - examples/sampled/bin/sampled
33
34
  - examples/sampled/config/boot.rb
34
35
  - examples/sampled/config/environment.rb
@@ -38,6 +39,9 @@ files:
38
39
  - examples/sampled/config/initializers/settings.rb
39
40
  - examples/sampled/config/settings.yml
40
41
  - examples/sampled/lib/sampled.rb
42
+ - examples/sampled/test/.keep
43
+ - examples/sampled/tmp/pids/.keep
44
+ - examples/sampled/vendor/.keep
41
45
  - examples/test.rb
42
46
  - lib/raemon.rb
43
47
  - lib/raemon/master.rb
@@ -73,6 +77,7 @@ specification_version: 3
73
77
  summary: Raemon is a Ruby framework for building UNIX daemons.
74
78
  test_files:
75
79
  - examples/beanstalk.rb
80
+ - examples/evented.rb
76
81
  - examples/sampled/config/boot.rb
77
82
  - examples/sampled/config/environment.rb
78
83
  - examples/sampled/config/environments/development.rb
@@ -80,4 +85,6 @@ test_files:
80
85
  - examples/sampled/config/environments/test.rb
81
86
  - examples/sampled/config/initializers/settings.rb
82
87
  - examples/sampled/lib/sampled.rb
88
+ - examples/sampled/test/example_test.rb
89
+ - examples/sampled/test/test_helper.rb
83
90
  - examples/test.rb