I wrote a tiny and very handy JMS drainer in JRuby with Spring at work, but I got fed up with running it from a command line because I am lazy.
So I wanted a web interface to run a drainer in background. Since I got JRuby on Rails in Tomcat running, I checked out BackgroundDRb only briefly, or not harder enough to get it working. To be honest, I could not figure out how I run a JRuby script as task.
Anyway, I came up with a better and simpler solution. I don’t need a fully featured background tasks management for this. I don’t need to persist tasks nor schedule tasks. I don’t care if tasks were terminated in the middle. The only things I need are:
- Run a task from a web form
- Show running tasks
I played with JSON and Jetty in JRuby before and found that combination very easy to develop. I have also learnt jQuery to work with JSON at client side recently. So I have used them to implement the above the followings.
-
Make a standalone JRuby task class runnable in a Java thread
-
A servlet in Jetty in JRuby with POST to execute a task in a thread and store the task instance in a global array and GET to return a list of running tasks of their status in JSON.
-
A default servlet in Jetty in JRuby to serve static content, i.e. one HTML page with css, javascripts and images
-
Use jQuery Ajax to load a JSON from the local servlet and populate the task list table dynamically.
That is simple and works well. It scales, too. 20-odd JMS drainers can run in one JVM. The execution is faster and save loads on the server.
I might post sample codes here if anyone is interested in.



No comments
Comments feed for this article