Permalink
Browse files

version 0.2.0, now with cherry flavor

  • Loading branch information...
1 parent 092079f commit 03ba9d4857db4b2a5215600c3d549a35388fe843 @ssoroka committed Jul 23, 2009
Showing with 150 additions and 45 deletions.
  1. +1 −0 .gitignore
  2. +6 −0 CHANGES
  3. +12 −1 README.markdown
  4. +51 −15 Rakefile
  5. +12 −19 generators/scheduler/templates/lib/scheduler.rb
  6. +53 −0 scheduler_daemon.gemspec
  7. +7 −0 spec/daemon_spec.rb
  8. +8 −0 spec/spec_helper.rb
  9. +0 −7 test/daemon_test.rb
  10. +0 −3 test/test_helper.rb
View
@@ -0,0 +1 @@
+pkg
View
@@ -0,0 +1,6 @@
+Version 0.2.0
+
+- syntax to load up only selected tasks for testing, by partial name:
+
+ ruby daemons/bin/task_runner.rb run -- --only=toadcamp,newsfeed
+
View
@@ -56,7 +56,18 @@ fire up the daemon in console mode to test it out
When you're done, get your system admin (or switch hats) to add the daemon to the system start-up, and
capistrano deploy scripts, etc. Something like:
- ruby /path/to/rails/app/scheduler/bin/scheduler_daemon.rb start
+ RAILS_ENV=production ruby /path/to/rails/app/scheduler/bin/scheduler_daemon.rb start
+
+Test individual tasks like so:
+
+ ruby daemons/bin/task_runner.rb run -- --only=task_name1,task_name2
+
+To Do
+=====
+
+- Settings file for certain variables like log directory
+- dynamically add and remove tasks while daemon is running (? anyone want this?)
+- tinder/campfire integration
Author
======
View
@@ -1,23 +1,59 @@
+require 'rubygems'
require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-desc 'Default: run unit tests.'
-task :default => :test
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "scheduler_daemon"
+ gem.summary = %Q{Rails 2.3.2 compatible scheduler daemon. Replaces cron/rake pattern of periodically running rake tasks
+ to perform maintenance tasks in Rails apps. Scheduler Daemon is made specifically for your Rails app,
+ and only loads the environment once, no matter how many tasks run.
+
+ What's so great about it? Well, I'm glad you asked!
+
+ - Only loads your Rails environment once on daemon start, not every time a task is run
+ - Allows you to easily deploy the scheduled tasks with your Rails app instead of depending on an
+ administrator to update crontab
+ - It doesn't use rake or cron!
+ - Gets you up and running with your own daemon in under 2 minutes
+ }
+ gem.email = "ssoroka78@gmail.com"
+ gem.homepage = "http://github.com/ssoroka/scheduler_daemon"
+ gem.authors = ["Steven Soroka"]
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+ end
+
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
+end
+
+require 'spec/rake/spectask'
+Spec::Rake::SpecTask.new(:spec) do |spec|
+ spec.libs << 'lib' << 'spec'
+ spec.spec_files = FileList['spec/**/*_spec.rb']
+end
-desc 'Test the gamey plugin.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.libs << 'test'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
+Spec::Rake::SpecTask.new(:rcov) do |spec|
+ spec.libs << 'lib' << 'spec'
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov = true
end
-desc 'Generate documentation for the gamey plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
+
+task :default => :spec
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ if File.exist?('VERSION.yml')
+ config = YAML.load(File.read('VERSION.yml'))
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
+ else
+ version = ""
+ end
+
rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'Gamey'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
+ rdoc.title = "scheduler_daemon #{version}"
+ rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
+
@@ -6,6 +6,9 @@
puts "Loaded #{Rails.env} environment"
end
+# allow ruby daemons/bin/task_runner.rb run -- --only=toadcamp,newsfeed
+load_only = ARGV.detect{|arg| arg =~ /^--only/}.split('=').last.split(',')
+
require 'eventmachine'
require 'rufus/scheduler'
@@ -19,10 +22,12 @@ def puts(*args)
tasks = []
Dir[File.join(File.dirname(__FILE__), %w(scheduled_tasks *.rb))].each{|f|
begin
- require f
- filename = f.split('/').last.split('.').first
- puts "Loading task #{filename}..."
- tasks << filename.camelcase.constantize # path/newsfeed_task.rb => NewsfeedTask
+ unless load_only.any? && load_only.all?{|m| f !~ Regexp.new(Regexp.escape(m)) }
+ require f
+ filename = f.split('/').last.split('.').first
+ puts "Loading task #{filename}..."
+ tasks << filename.camelcase.constantize # path/newsfeed_task.rb => NewsfeedTask
+ end
rescue
end
}
@@ -43,20 +48,8 @@ def puts(*args)
end
def scheduler.handle_exception(job, exception)
- puts "job #{job.job_id} caught exception '#{exception}'"
+ puts "[#{Rails.env}] scheduler job #{job.job_id} caught exception #{exception.inspect}"
+ # If your team all hangs out in Campfire, you might want to try
+ # something like Tinder here to write these messages out to campfire.
end
}
-
-# # other examples:
-# scheduler.cron '0 22 * * 1-5' do
-# # every day of the week at 00:22
-# puts 'activate security system'
-# end
-#
-# scheduler.every '2d', :timeout => '40m' do
-# begin
-# run_backlog_cleaning()
-# rescue Rufus::Scheduler::TimeOutError => toe
-# # timeout occurred
-# end
-# end
View
@@ -0,0 +1,53 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{scheduler_daemon}
+ s.version = "0.2.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Steven Soroka"]
+ s.date = %q{2009-07-23}
+ s.email = %q{ssoroka78@gmail.com}
+ s.extra_rdoc_files = [
+ "README.markdown"
+ ]
+ s.files = [
+ "CHANGES",
+ "MIT-LICENSE",
+ "README.markdown",
+ "Rakefile",
+ "VERSION",
+ "generators/scheduler/USAGE",
+ "generators/scheduler/scheduler_generator.rb",
+ "generators/scheduler/templates/README",
+ "generators/scheduler/templates/bin/scheduler_daemon.rb",
+ "generators/scheduler/templates/lib/scheduler.rb",
+ "generators/scheduler_task/scheduler_task_generator.rb",
+ "generators/scheduler_task/templates/README",
+ "generators/scheduler_task/templates/scheduled_tasks/example_task.rb",
+ "init.rb",
+ "install.rb",
+ "lib/scheduler.rb",
+ "scheduler_daemon.gemspec",
+ "uninstall.rb"
+ ]
+ s.homepage = %q{http://github.com/ssoroka/scheduler_daemon}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.3}
+ s.summary = %q{Rails 2.3.2 compatible scheduler daemon. Replaces cron/rake pattern of periodically running rake tasks to perform maintenance tasks in Rails apps. Scheduler Daemon is made specifically for your Rails app, and only loads the environment once, no matter how many tasks run. What's so great about it? Well, I'm glad you asked! - Only loads your Rails environment once on daemon start, not every time a task is run - Allows you to easily deploy the scheduled tasks with your Rails app instead of depending on an administrator to update crontab - It doesn't use rake or cron! - Gets you up and running with your own daemon in under 2 minutes}
+ s.test_files = [
+ "spec/daemon_spec.rb",
+ "spec/spec_helper.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
View
@@ -0,0 +1,7 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe "scheduler daemon" do
+ it "passes" do
+ # I just test it manually and use it in production in another project before features make it here. Cut me some slack, eh?
+ end
+end
View
@@ -0,0 +1,8 @@
+require 'spec'
+
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+
+Spec::Runner.configure do |config|
+
+end
View
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class DaemonTest < ActiveSupport::TestCase
- test "" do
- assert true
- end
-end
View
@@ -1,3 +0,0 @@
-require 'rubygems'
-require 'active_support'
-require 'active_support/test_case'

0 comments on commit 03ba9d4

Please sign in to comment.