jruby-rack-worker 0.2-jruby → 0.3-jruby

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/README.md CHANGED
@@ -3,29 +3,36 @@ JRuby Rack Worker
3
3
 
4
4
  Java based thread worker implementation over [jruby-rack](http://github.com/nicksieger/jruby-rack).
5
5
 
6
+ Natively supports [Delayed::Job](http://github.com/collectiveidea/delayed_job) and
7
+ [Navvy](http://github.com/jeffkreeftmeijer/navvy) but one can easily write his own
8
+ worker loop.
9
+
10
+
6
11
  Motivation
7
12
  ----------
8
13
 
9
14
  While migrating a rails application to [JRuby](http://jruby.org) I found myself
10
15
  stuck with [Delayed::Job](http://github.com/collectiveidea/delayed_job). I wanted
11
16
  to deploy the application without having to spawn a separate daemon process in
12
- another *ruby* (as *jruby* is not daemonizable the [daemons](http://daemons.rubyforge.org) way).
17
+ another *Ruby* (as *JRuby* is not daemonizable the [daemons](http://daemons.rubyforge.org)
18
+ way).
13
19
 
14
20
  Well, why not spawn a "daemon" thread looping over the jobs from the servlet
15
21
  container ... after all the java world is inherently thread-oriented !
16
22
 
17
23
  This does have the advantage of keeping the deployment simple and saving some
18
- precious memory (assuming `threadsafe!` mode of course) that would have been
24
+ precious memory (most notably with `threadsafe!` mode) that would have been
19
25
  eaten by the separate process. Besides Your daemons start benefiting from
20
- JRuby's (as well as Java's) runtime optimalizations !
26
+ JRuby's (as well as Java's) runtime optimalizations ...
21
27
 
22
28
  On the other hand Your jobs should be simple and complete "fast" (in a rate of
23
29
  seconds rather than several minutes or hours) as they will restart and live with
24
- the lifecycle of the deployed application / application server.
30
+ the lifecycle of the deployed application and/or application server.
25
31
 
26
32
  Java purist might objects the servlet specification does not advise spawning
27
33
  daemon threads in a servlet container, objection noted. Whether this style of
28
- asynchronous processing suits Your limits, needs and taste is entirely up to U !
34
+ asynchronous processing suits Your limits, needs and taste is entirely up to
35
+ You.
29
36
 
30
37
 
31
38
  Setup
@@ -34,9 +41,9 @@ Setup
34
41
  Copy the `jruby-rack-worker.jar` into the `lib` folder or the directory being
35
42
  mapped to `WEB-INF/lib` e.g. `lib/java`.
36
43
 
37
- Configure the worker in Your `web.xml`, You'll need to add a servlet context
38
- listener that will start threads when You application boots and a script to be
39
- executed (should be an "endless" loop-ing script). Sample configuration :
44
+ Configure the worker in `web.xml`, You'll need to add a servlet context listener
45
+ that will start threads when You application boots and a script to be executed
46
+ (should be an "endless" loop-ing script). Sample configuration :
40
47
 
41
48
  <context-param>
42
49
  <param-name>jruby.worker.script</param-name>
@@ -50,42 +57,50 @@ executed (should be an "endless" loop-ing script). Sample configuration :
50
57
  <listener-class>org.kares.jruby.rack.WorkerContextListener</listener-class>
51
58
  </listener>
52
59
 
53
- <strong>
54
- Script loading from WEB-INF/lib/*.jar files is not working thus make sure
55
- (in case of the above example) that You copy all Your .rb files to the load path
56
- (e.g. in case of the above example copy `src/main/ruby/delayed/jruby_worker.rb`
57
- to `RAILS_ROOT/lib/delayed/jruby_worker.rb` ) ...
58
- </strong>
59
-
60
60
  **NOTE**: The `WorkerContextListener` needs to be executed (and thus configured)
61
61
  after the `RailsServletContextListener`/`RackServletContextListener` as it expects
62
- the jruby-rack environment to be available.
62
+ the *jruby-rack* environment to be available.
63
63
 
64
64
  **NOTE**: If You're not using `threadsafe!` than You really **should** ...
65
65
 
66
66
  **NOTE**: If You're still not using `threadsafe!` mode than You're polling several
67
- (non-thread-safe) jruby runtimes instances while serving requests, the *workers
68
- run as part of Your application* thus each worker thread will remove and use an
69
- application runtime from Your instance pool (consider it while setting the
70
- `jruby.min.runtimes`/`jruby.max.runtimes` parameters) !
67
+ (non-thread-safe) JRuby runtimes instances while serving requests, the *workers
68
+ are nor running as a part of the application* thus each worker thread will remove
69
+ and use (block) an application runtime from the instance pool (consider it while
70
+ setting the `jruby.min.runtimes`/`jruby.max.runtimes` parameters) !
71
71
 
72
72
  Sample Rails `web.xml` usable with [Warbler](http://caldersphere.rubyforge.org/warbler)
73
73
  including optional configuration parameters
74
74
  [web.xml](/kares/jruby-rack-worker/blob/master/src/test/resources/warbler.web.xml).
75
75
 
76
+ A simpler configuration using the built-in `Delayed::Job` / `Navvy` support :
77
+
78
+ <context-param>
79
+ <param-name>jruby.worker</param-name>
80
+ <param-value>delayed_job</param-value> <!-- or navvy -->
81
+ </context-param>
82
+
83
+ <listener>
84
+ <listener-class>org.kares.jruby.rack.WorkerContextListener</listener-class>
85
+ </listener>
86
+
76
87
 
77
88
  Build
78
89
  =====
79
90
 
80
91
  [JRuby](http://jruby.org) 1.5+ is required to build the project.
81
92
  The build is performed by [rake](http://rake.rubyforge.org) which should be part
82
- of Your JRuby installation, if You're experiencing conflicts with another Ruby and
93
+ of the JRuby installation, if You're experiencing conflicts with another Ruby and
83
94
  it's rake executable use `jruby -S rake` instead of the bare `rake` command.
84
95
 
85
96
  Build the `jruby-rack-worker.jar` using :
86
97
 
87
98
  rake jar
88
99
 
100
+ Build the gem (includes the jar) :
101
+
102
+ rake gem
103
+
89
104
  Run the tests with :
90
105
 
91
106
  rake test
@@ -95,22 +110,24 @@ Worker Migration
95
110
  ================
96
111
 
97
112
  There are a few gotchas to keep in mind when migrating a worker such as
98
- [Delayed::Job](http://github.com/collectiveidea/delayed_job) to JRuby, You'll most
99
- probably need to start by looking at Your worker spawning script (such as `script/delayed_job`) :
113
+ [Delayed::Job](http://github.com/collectiveidea/delayed_job) to JRuby, You'll
114
+ most probably need to start by looking at the current worker spawning script
115
+ (such as `script/delayed_job`) :
100
116
 
101
117
  * avoid native gems such as daemons (in DJ's case this means avoiding the whole
102
118
  `Delayed::Command` implementation)
103
119
 
104
120
  * remove command line processing - all Your configuration should happen in an
105
- initializer or the `web.xml`
121
+ application initializer or the `web.xml`
106
122
 
107
- * make sure the worker code is thread-safe in case Your application is running in
108
- `threadsafe!` mode (make sure no global state is changing by the worker or
123
+ * make sure the worker code is thread-safe in case Your application is running
124
+ in `threadsafe!` mode (make sure no global state is changing by the worker or
109
125
  class variables are not being used to store worker state)
110
126
 
111
127
  * refactor Your worker's exit code from a (process oriented) signal based `trap`
112
- to `at_exit` - respects better the JRuby servlet environment Your workers be
113
- running in
128
+ to `at_exit` - which respects better the JRuby environment Your workers are
129
+ going to run in
130
+
114
131
 
115
132
  See the [Delayed::Job](/kares/jruby-rack-worker/tree/master/src/main/ruby/delayed)
116
- JRuby "migrated" worker code for inspiration.
133
+ JRuby "adapted" worker code for inspiration.
Binary file
@@ -1,7 +1,7 @@
1
1
  module JRuby
2
2
  module Rack
3
3
  module Worker
4
- VERSION = '0.2'
4
+ VERSION = '0.3'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jruby-rack-worker
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: "0.2"
5
+ version: "0.3"
6
6
  platform: jruby
7
7
  authors:
8
8
  - Karol Bucek
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-12 00:00:00 +02:00
13
+ date: 2011-04-24 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -36,8 +36,8 @@ extra_rdoc_files: []
36
36
  files:
37
37
  - README.md
38
38
  - LICENSE
39
- - lib/jruby-rack-worker_0.2.jar
40
39
  - lib/jruby_rack_worker.rb
40
+ - lib/jruby-rack-worker_0.3.jar
41
41
  - lib/jruby/rack/worker/version.rb
42
42
  has_rdoc: true
43
43
  homepage: http://github.com/kares/jruby-rack-worker
Binary file