Project

daemonz

0.0
No commit activity in last 3 years
No release in over 3 years
Works with Facebook.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.2.0
>= 1.0.2
>= 1.8.4
>= 0.9.2.2
>= 0
>= 1.3.6

Runtime

>= 0.3.6
>= 3.2.8
>= 0.1.5
 Project Readme

Daemonz¶ ↑

Automatically starts and stops the daemons in a Rails application.

Installation¶ ↑

Add the following entry to your Gemfile:

gem 'daemonz'

Get the gem wired and generate the default configuration:

bundle install
rails g daemonz:config

You don’t need to do anything in your code for daemonz to work. It will start the daemons when your server starts, and stop them when your server exits. It does work with multiple servers.

Configuration¶ ↑

The main configuration file is config/daemonz.yml. Daemons are configured by individual files in the config/daemonz directory. Configuration files are ran through Erb, so you can go crazy.

Daemonz comes with a few configuration examples that can also be used as they are, by removing the line containing “:disabled: true”. Please contribute your configuration if you think others could use it.

Daemon Generator¶ ↑

Daemonz includes a generator for a daemon intended to do background processing inside a Rails environment. If you’re writing your first daemon, give it a try. The scaffolded code includes the configuration file, a daemon skeleton using the simple-daemon gem, and an integration test skeleton.

rails g daemon YourDaemonName

Testing¶ ↑

You can test your daemonz configuration with rake, as shown below. Keep in mind that the Rake tasks are only provided for testing, and you should not use them while your Rails application is running. Nothing bad should happen if you run the tasks by mistake, but things may go astray if you mix the Rake tasks with application starts and stops.

rake daemons:start # Starts your daemons (for testing only)
rake daemons:stop  # Stops your daemons (for testing only)

Using the default configuration, daemons are not running during tests. The snippet below shows how you can have daemons running during a specific test.

class DaemonsTest < ActionController::IntegrationTest
  # If this isn't here, Rails runs the entire test in a transaction, so
  # the database changes performed by daemons won't be visible to the test
  # code.
  #
  # Keep in mind that SQLite can't do multi-process access, so you'll need
  # to upgrade to a database server, such as MySQL or PostgreSQL if you're
  # accessing the database from your daemons.
  self.use_transactional_fixtures = false

  test "something needing daemons" do
    Daemonz.with_daemons do
      # daemons will be alive while this code is executed
    end
  end
end

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2008-2012 Victor Costan, released under the MIT license