Permalink
Browse files

removed examples from gem, updated readme & version

  • Loading branch information...
1 parent 6cef3a1 commit 52be25ff7bfa7671427ba402e25d7ac1a1260158 craigp committed Jul 27, 2010
Showing with 131 additions and 86 deletions.
  1. +106 −9 README.rdoc
  2. +4 −2 Rakefile
  3. +1 −1 VERSION
  4. +3 −62 djinn.gemspec
  5. +14 −9 example/basic.rb
  6. +1 −3 example/rails/demo/script/book_djinn
  7. +2 −0 lib/djinn/base.rb
View
@@ -1,16 +1,113 @@
= djinn
-Description goes here.
+Djinn is a very basic helper for building simple daemons
-== Note on Patches/Pull Requests
+== Non-Rails Example
+
+#!/usr/bin/env ruby
+
+ require 'rubygems'
+ require 'djinn'
+
+ class Basic
+
+ include Djinn
+
+ # Not providing a "perform" method falls back to the base method
+ # in Djinn, which does nothing useful. Make sure your method accepts
+ # a config hash, even if it doesn't use it.
+ def perform options
+ log "ZOMG! A Djinn?"
+ end
+
+ # Strictly optional, lets you do stuff when the Djinn daemon stops.
+ # The call to "super" is required, or your daemon will never die
+ def handle_exit
+ log "Handling a nice graceful exit.."
+ super
+ end
+
+ end
+
+Run it in the foreground like this:
+
+ djinn = Basic.new
+ djinn.run
+
+But running it in the background is sort of the point. A bit contrived, but
+this is the general idea:
+
+ djinn.start
+ sleep(10)
+ djinn.stop
+
+== Rails Example
+
+There's a nice example in the example directory if you check the code out, but
+here's the gist of it.
+
+Assumes a scenario where you have a Book model that keeps a count of how many
+times a book has been read.
+
+Create a file in RAILS_ROOT/lib or somewhere similar:
+
+ BOOK_WORKER_INTERVAL = 5
+
+ class BookDjinn
+
+ require 'djinn/rails'
+
+ include Djinn::Rails
+
+ def perform config
+ EM.run do
+ log "Workers will run every #{BOOK_WORKER_INTERVAL} secs"
+ EM::PeriodicTimer.new(BOOK_WORKER_INTERVAL) do
+ log "There are #{Book.count} book(s) in the database"
+ log "Updating read counts for all books.."
+ Book.all.each &:read!
+ end
+ end
+ end
+
+ def handle_exit
+ EM.stop
+ super
+ end
+
+ end
+
+Right, now you need to start it somehow. The easiest way is to create a file
+in RAILS_ROOT/scripts and pop this in it:
+
+ #!/usr/bin/env ruby
+ require 'rubygems'
+ require File.join(File.dirname(__FILE__), '../lib/book_djinn')
+ BookDjinn.go ARGV
-* 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.
+Righto, now start it from RAILS_ROOT:
+
+ ruby script/book_djinn
+
+Okay, but that defaults to "run", which starts it in the foreground and also
+uses the rails development environment by default. Try this:
+
+ ruby script/book_djinn --help
+
+That should give you a better idea of what's going on, then try this:
+
+ ruby script/book_djinn start -e production
+
+Yay, we have a daemon running in the background! To stop it:
+
+ ruby script/book_djinn stop
+
+That gives you more-or-less everything you need to build something basic
+and monitor it with god or a similar process monitor.
+
+== TODO
+
+ Lots. Keep 'em peeled.
== Copyright
View
@@ -5,12 +5,14 @@ begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "djinn"
- gem.summary = %Q{Simple helper for creating daemons}
- gem.description = %Q{Helper for creating custom daemon, mostly for rails}
+ gem.summary = %Q{Helper for creating simple custom daemons}
+ gem.description = %Q{Helper for creating simple custom daemons}
gem.email = "darksavant@gmail.com"
gem.homepage = "http://github.com/craigp/djinn"
gem.authors = ["Craig Paterson"]
gem.add_development_dependency "shoulda", ">= 2.11.1"
+ gem.files.exclude 'example/**/*'
+ gem.test_files.exclude 'example/**/*'
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
View
@@ -1 +1 @@
-0.0.3
+0.0.5
View
@@ -5,12 +5,12 @@
Gem::Specification.new do |s|
s.name = %q{djinn}
- s.version = "0.0.3"
+ s.version = "0.0.4"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Craig Paterson"]
s.date = %q{2010-07-27}
- s.description = %q{Helper for creating custom daemon, mostly for rails}
+ s.description = %q{Helper for creating simple custom daemons}
s.email = %q{darksavant@gmail.com}
s.extra_rdoc_files = [
"LICENSE",
@@ -24,65 +24,6 @@ Gem::Specification.new do |s|
"Rakefile",
"VERSION",
"djinn.gemspec",
- "example/basic.rb",
- "example/em.rb",
- "example/event_machine_djinn.pid",
- "example/rails/demo/Rakefile",
- "example/rails/demo/app/controllers/application_controller.rb",
- "example/rails/demo/app/controllers/books_controller.rb",
- "example/rails/demo/app/helpers/application_helper.rb",
- "example/rails/demo/app/helpers/books_helper.rb",
- "example/rails/demo/app/models/book.rb",
- "example/rails/demo/app/views/books/_book.html.erb",
- "example/rails/demo/app/views/books/index.html.erb",
- "example/rails/demo/app/views/layouts/application.html.erb",
- "example/rails/demo/config/boot.rb",
- "example/rails/demo/config/database.yml",
- "example/rails/demo/config/environment.rb",
- "example/rails/demo/config/environments/development.rb",
- "example/rails/demo/config/environments/production.rb",
- "example/rails/demo/config/environments/test.rb",
- "example/rails/demo/config/initializers/backtrace_silencers.rb",
- "example/rails/demo/config/initializers/cookie_verification_secret.rb",
- "example/rails/demo/config/initializers/inflections.rb",
- "example/rails/demo/config/initializers/mime_types.rb",
- "example/rails/demo/config/initializers/new_rails_defaults.rb",
- "example/rails/demo/config/initializers/session_store.rb",
- "example/rails/demo/config/locales/en.yml",
- "example/rails/demo/config/routes.rb",
- "example/rails/demo/db/migrate/20100726151602_create_books.rb",
- "example/rails/demo/db/schema.rb",
- "example/rails/demo/db/seeds.rb",
- "example/rails/demo/doc/README_FOR_APP",
- "example/rails/demo/lib/book_djinn.rb",
- "example/rails/demo/public/404.html",
- "example/rails/demo/public/422.html",
- "example/rails/demo/public/500.html",
- "example/rails/demo/public/favicon.ico",
- "example/rails/demo/public/images/rails.png",
- "example/rails/demo/public/javascripts/application.js",
- "example/rails/demo/public/javascripts/controls.js",
- "example/rails/demo/public/javascripts/dragdrop.js",
- "example/rails/demo/public/javascripts/effects.js",
- "example/rails/demo/public/javascripts/prototype.js",
- "example/rails/demo/public/robots.txt",
- "example/rails/demo/script/about",
- "example/rails/demo/script/book_djinn",
- "example/rails/demo/script/console",
- "example/rails/demo/script/dbconsole",
- "example/rails/demo/script/destroy",
- "example/rails/demo/script/generate",
- "example/rails/demo/script/performance/benchmarker",
- "example/rails/demo/script/performance/profiler",
- "example/rails/demo/script/plugin",
- "example/rails/demo/script/runner",
- "example/rails/demo/script/server",
- "example/rails/demo/test/fixtures/books.yml",
- "example/rails/demo/test/functional/books_controller_test.rb",
- "example/rails/demo/test/performance/browsing_test.rb",
- "example/rails/demo/test/test_helper.rb",
- "example/rails/demo/test/unit/book_test.rb",
- "example/rails/demo/test/unit/helpers/books_helper_test.rb",
"lib/djinn.rb",
"lib/djinn/base.rb",
"lib/djinn/logging.rb",
@@ -97,7 +38,7 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
- s.summary = %q{Simple helper for creating daemons}
+ s.summary = %q{Helper for creating simple custom daemons}
s.test_files = [
"test/helper.rb",
"test/test_djinn.rb"
View
@@ -1,18 +1,23 @@
#!/usr/bin/env ruby
-$:.unshift(File.join(File.dirname(__FILE__), "../lib/"))
-
+require 'rubygems'
require 'djinn'
class Basic
include Djinn
- # not providing a "perform" method falls back to the
- # base method in Djinn..
+ # Not providing a "perform" method falls back to the base method
+ # in Djinn, which does nothing useful. Make sure your method accepts
+ # a config hash, even if it doesn't use it.
+ def perform options
+ log "ZOMG! A Djinn?"
+ end
+ # Strictly optional, lets you do stuff when the Djinn daemon stops.
+ # The call to "super" is required, or your daemon will never die
def handle_exit
- puts "Handling a nice graceful exit.."
+ log "Handling a nice graceful exit.."
super
end
@@ -21,7 +26,7 @@ def handle_exit
djinn = Basic.new
djinn.run
-# puts "Running for 10 secs in the background and then stopping.."
-# djinn.start
-# sleep(10)
-# djinn.stop
+# Runs for 10 secs in the background and then stops
+djinn.start
+sleep(10)
+djinn.stop
@@ -1,7 +1,5 @@
#!/usr/bin/env ruby
-
-$:.unshift('/Users/macbookpro/source/craigp/djinn/lib')
+require 'rubygems'
require File.join(File.dirname(__FILE__), '../lib/book_djinn')
-
BookDjinn.go ARGV
View
@@ -1,3 +1,5 @@
+$:.unshift(File.dirname(__FILE__))
+
require 'tonic'
require 'pid_file'
require 'logging'

0 comments on commit 52be25f

Please sign in to comment.