Permalink
Browse files

Bump to version 0.3.0.a

  • Loading branch information...
1 parent 0e8b691 commit 8b4f47494aa4abcce717f1263403c5bfc718dc72 @DAddYE committed Oct 4, 2011
Showing with 316 additions and 156 deletions.
  1. +6 −0 CHANGES.md
  2. +63 −3 README.md
  3. +18 −8 Rakefile
  4. +3 −11 examples/{sample → complex}
  5. +32 −0 examples/simple
  6. +12 −0 examples/stress
  7. +1 −0 examples/tmp/complex.pid
  8. +1 −1 foreverb.gemspec
  9. +8 −8 lib/forever.rb
  10. +83 −37 lib/forever/base.rb
  11. +23 −10 lib/forever/every.rb
  12. +1 −1 lib/forever/version.rb
  13. +19 −19 spec/cli_spec.rb
  14. +33 −33 spec/foreverb_spec.rb
  15. +13 −25 spec/spec_helper.rb
View
@@ -1,3 +1,9 @@
+# Version 0.3.0 - October 4, 2011
+
+* Added fork backend
+* Improved queue
+* Added before/after each/all filters
+
# Version 0.2.6 - August 27, 2011
* Added back support for update the daemon config
View
@@ -14,6 +14,8 @@ In my servers I've several daemons and what I need is:
* easily manage exceptions
* easily see logs
* easily start/stop/restart daemon
+* no blocking jobs
+* no blocking queue
As like [sinatra](https://github.com/sinatra/sinatra) and [padrino](https://github.com/padrino/padrino-framework) I need a
**thin** framework to do these jobs in few seconds. This mean that:
@@ -61,7 +63,7 @@ Forever.run do
end
end
- on_ready do
+ before :each do # or if you prefer before :all
require 'bundler/setup'
require 'foo'
Foo.start_loop
@@ -124,7 +126,7 @@ So looking our [example](https://github.com/DAddYE/foreverb/blob/master/examples
Forever.run do
dir File.expand_path('../', __FILE__) # Default is ../../__FILE__
- on_ready do
+ before :all do
puts "All jobs will will wait me for 1 second"; sleep 1
end
@@ -146,6 +148,7 @@ Forever.run do
every 15.seconds do
puts "Every 15 seconds, but my task require 10 seconds"; sleep 10
+ # This doesn't block other jobs and your queue !!!!!!!
end
every 10.seconds, :at => [":#{Time.now.min+1}", ":#{Time.now.min+2}"] do
@@ -207,6 +210,30 @@ you should see:
[14/07 15:48:40] Bye bye
```
+## Filters
+
+In foreverb we have a couple of filters, `before` and `after`, like rspec you should be able to filter `before :all` or `before :each`.
+
+``` rb
+before :all do
+ puts "This will be ran only at start"
+end
+
+before :each do
+ puts "Do that before each job"
+end
+
+# ... here jobs ...
+
+after :all do
+ puts "This will be ran only at shutdown"
+end
+
+after :each do
+ puts "Do that after each job"
+end
+```
+
## CLI
### Help:
@@ -307,13 +334,46 @@ as for stop we allow `--all` and `-y`
## HACKS
+### Bundler
+
Bundler has the bad behavior to load `Gemfile` from your current path, so if your `daemons` (ex: [githubwatcher](https://github.com/daddye/githubwatcher))
is shipped with their own `Gemfile` to prevent errors you must insert that line:
``` ruby
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__) # edit matching your Gemfile path
```
+### Rails/Padrino prevent memory leaks
+
+I highly suggest to use `fork` and `before` filters when you are using `forever` with frameworks, this since running same job on our ruby will eat a lot of
+ram, so the better way that I found is that:
+
+```rb
+Forever.run :fork => true do
+ before :each do
+ require '/config/boot' # here the rails/padrino environment
+ end
+
+ every 10.seconds, :at => ['12:00', '00:00'] do
+ Project.all(&:perform_long_task)
+ end
+
+ every 1.minute do
+ Account.all.map(&:send_emails)
+ end
+end
+```
+
+This is similar to create a new process i.e.:
+
+```rb
+Process.fork do
+ require '/config/boot'
+ my_long_jobs
+end
+Process.waitall
+```
+
## Extras
To see a most comprensive app running _foreverb_ + _growl_ see [githubwatcher gem](https://github.com/daddye/githubwatcher)
@@ -336,4 +396,4 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,30 +1,40 @@
require 'rubygems' unless defined?(Gem)
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
+require 'rake/testtask'
%w(install release).each do |task|
Rake::Task[task].enhance do
sh "rm -rf pkg"
end
end
-desc "Bump version on github"
+desc 'Bump version on github'
task :bump do
- if `git status -s`.strip == ""
+ if `git status -s`.strip == ''
puts "\e[31mNothing to commit (working directory clean)\e[0m"
else
version = Bundler.load_gemspec(Dir[File.expand_path('../*.gemspec', __FILE__)].first).version
sh "git add .; git commit -a -m \"Bump to version #{version}\""
end
end
-task :release => :bump
+Rake::TestTask.new(:spec) do |t|
+ t.test_files = Dir['spec/**/*_spec.rb']
+ t.verbose = true
+end
-desc "Run complete application spec suite"
-RSpec::Core::RakeTask.new("spec") do |t|
- t.skip_bundler = true
- t.pattern = './spec/**/*_spec.rb'
- t.rspec_opts = %w(-fs --color --fail-fast)
+namespace :example do
+ Dir['./examples/*'].each do |path|
+ next if File.directory?(path)
+ name = File.basename(path)
+ desc "Run example #{name}"
+ task name, :fork do |t, args|
+ ENV['FORK'] = args[:fork]
+ exec "#{Gem.ruby} #{path} && sleep 3 && tail -f -n 150 #{path}/../log/#{name}.log; #{path} stop"
+ end
+ end
end
+task :release => :bump
task :default => :spec
@@ -3,7 +3,7 @@ require 'rubygems' unless defined?(Gem)
require 'bundler/setup'
require 'forever'
-Forever.run do
+Forever.run :fork => ENV['FORK'] do
dir File.expand_path('../', __FILE__) # Default is ../../__FILE__
every 5.seconds do
@@ -14,19 +14,11 @@ Forever.run do
puts "All jobs will will wait me for 1 second"; sleep 1
end
- every 5.seconds, :last => Time.now do
- puts "Every 5 seconds from start"
- end
-
- every 30.seconds, :last => Time.now do
+ every 30.seconds do
puts "Every 30 seconds from start with boom"
raise "woooooa"
end
- every 10.seconds, :at => "#{Time.now.hour}:00" do
- puts "Every 10 seconds but first call at #{Time.now.hour}:00"
- end
-
every 1.seconds, :at => "#{Time.now.hour}:#{Time.now.min+1}" do
puts "Every one second but first call at #{Time.now.hour}:#{Time.now.min}"
end
@@ -40,7 +32,7 @@ Forever.run do
end
every 15.seconds do
- puts "Every 15 seconds, but my task require 10 seconds"; sleep 10
+ puts "Every 15 seconds, but my task requires 10 seconds"; sleep 10
end
every 10.seconds, :at => [":#{Time.now.min+1}", ":#{Time.now.min+2}"] do
View
@@ -0,0 +1,32 @@
+#!/usr/bin/ruby
+require 'rubygems' unless defined?(Gem)
+require 'bundler/setup'
+require 'forever'
+
+Forever.run :fork => ENV['FORK'] do
+ dir File.expand_path('../', __FILE__) # Default is ../../__FILE__
+
+ before :each do
+ puts 'before all'
+ end
+
+ after :each do
+ puts 'after all'
+ end
+
+ every 1.seconds do
+ puts 'wait me 10 seconds'; sleep 10
+ end
+
+ every 2.seconds do
+ puts 'every 2 seconds'
+ end
+
+ on_ready do
+ puts "All jobs will will wait me for 1 second"; sleep 1
+ end
+
+ on_exit do
+ puts "Bye bye"
+ end
+end
View
@@ -0,0 +1,12 @@
+#!/usr/bin/ruby
+require 'rubygems' unless defined?(Gem)
+require 'bundler/setup'
+require 'forever'
+
+Forever.run :fork => ENV['FORK'] do
+ dir File.expand_path('../', __FILE__) # Default is ../../__FILE__
+
+ (1..40).each do |i|
+ every(i.seconds) { puts 'Every %d seconds' % i; sleep i }
+ end
+end
View
@@ -0,0 +1 @@
+32947
View
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = %w(lib)
s.add_dependency 'thor', '~>0.14.6'
- s.add_development_dependency 'rspec', '~>2.6.0'
+ s.add_development_dependency 'minitest'
end
View
@@ -1,10 +1,10 @@
require 'yaml' unless defined?(YAML)
-require "forever/extensions"
-require "forever/every"
-require "forever/base"
-require "forever/version"
+require 'forever/extensions'
+require 'forever/every'
+require 'forever/base'
+require 'forever/version'
-YAML::ENGINE.yamler = "syck" if defined?(YAML::ENGINE)
+YAML::ENGINE.yamler = 'syck' if defined?(YAML::ENGINE)
FOREVER_PATH = ENV['FOREVER_PATH'] ||= File.expand_path("~/.foreverb") unless defined?(FOREVER_PATH)
path = File.dirname(FOREVER_PATH)
@@ -15,8 +15,8 @@ module Forever
def run(options={}, &block)
caller_file = caller(1).map { |line| line.split(/:(?=\d|in )/)[0,1] }.flatten.first
- options[:dir] ||= File.expand_path('../../', caller_file) # => we presume we are calling it from a bin|script dir
- options[:file] ||= File.expand_path(caller_file)
+ options[:file] ||= File.expand_path(caller_file)
+ options[:dir] ||= File.expand_path('../../', options[:file]) # => we presume we are calling it from a bin|script dir
Base.new(options, &block)
end # run
-end # Forever
+end # Forever
Oops, something went wrong.

0 comments on commit 8b4f474

Please sign in to comment.