In this video, I demonstrate how TorqueBox scheduled jobs can be run in a cluster without duplicating the job across nodes.
To run the examples I've shown in the video, you'll need to install the torquebox-server gem to your JRuby runtime:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gem install torquebox-server -v 2.0.0.cr1 |
Here are the commands and code I run in the video:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ torquebox run --clustered | |
$ JBOSS_OPTS="-Djboss.node.name=node2 \ | |
-Djboss.server.data.dir=/tmp/node2 \ | |
-Djboss.socket.binding.port-offset=100" \ | |
torquebox run --clustered | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyJob | |
def run | |
puts "I'm a cod fish" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TorqueBox.configure do | |
job MyJob do | |
cron "0/1 * * * * ?" | |
singleton true | |
end | |
end |