daddye / foreverb Goto Github PK
View Code? Open in Web Editor NEWSmall daemon framework for ruby, with logging, error handler, scheduling and much more.
Home Page: https://github.com/DAddYE/foreverb
Small daemon framework for ruby, with logging, error handler, scheduling and much more.
Home Page: https://github.com/DAddYE/foreverb
I'm usign foreverb to run two daemon:
generate_roster_kids.rb
#!/usr/bin/ruby
require 'rubygems' unless defined?(Gem)
require 'forever'
require 'redis'
Forever.run do
REDIS = Redis.new()
log "bar.log" # Default: File.expand_path(dir, '/log/[file_name].log')
every 2.seconds do
REDIS.SUNIONSTORE :busy, REDIS.keys('Busy:*') rescue REDIS.SUNIONSTORE :busy, nil
REDIS.EXPIRE :busy, 3
REDIS.SUNIONSTORE :online, REDIS.keys('Online:*') rescue REDIS.SUNIONSTORE :online, nil
REDIS.EXPIRE :online, 3
end
end
booking_release.rb
#!/usr/bin/ruby
require 'rubygems' unless defined?(Gem)
require 'forever'
require File.expand_path("../../../config/environment", __FILE__)
Forever.run do
every 2.seconds do
@booking = Booking.where(booking_available: false, :created_at.lt => DateTime.now.to_datetime.in_time_zone("Madrid") - 10.minutes).to_a
@booking.each do |book|
if book.Ds_Response.nil?
book.booking_available = true
book.save!
puts "update #{book.id}"
end
end
puts "#{@booking.count}"
end
end
Those file are in my blabloo/script/user folder, as you can see the generate_roster_kids log on a file "bar.log", I have the log file on blabloo/script/log/bar.log but when I try to use the command foreverb tail generate_roster_kids or foreverb tail booking_release I always get:
tail: bar.log: No such file or directory
Also, a week ago I have a third daemon with the name of "classes_notification.rb" and now when I try to run foreverb start --all I get the following:
Do you want really start /Users/jeanosorio/repos/blabloo/script/user/generate_roster_kids.rb? Do you want really start /Users/jeanosorio/repos/blabloo/script/user/classes_notification.rb? Do you want really start /Users/jeanosorio/repos/blabloo/script/user/booking_release.rb?
but the classes_notification file does not exist. What I'm doing wrong???, how can I stop foreverb to ask me for the classes_notification daemon and what happen with the log file.
Thanks in advance for your help.
hi,
try to deploy an application with foreverrb with capistrano, at each deploy is created a new folder release.
Foreverb store the path to daemon with complete path to release instead of use link to symlink to current.
Is possible to write the path in file .foreverb with current instead of the full path to release?
Basically it seams #stop! isn't called. Should be by the trap clause I think, but it isn't. I can't tell why.
Is there a way to run the daemon in live mode with log output going to stdout instead of to the log file? That would be much easier to manage than start + tail.
Thanks
Forver on node can start normal .js files. Does foreverb have diffrent view on that usage? It would be lovely to just use foreverb start app.rb, or at least foreverb daemonize app.rb && forever start app.rb?
I don't know if that's an issue but I noticed that truncating the logfile (the redirected STDOUT) doesn't work, at least the way expected. When doing
echo '' > out.log
ls -l out.log
ls
still shows the old filesize. df
shows the diskspace being freed. The logfile contains somehow invisible characters. It seems the open file should be rewinded or seek the beginning again. I work around this with this code at the moment:
Signal.trap('USR2'){ STDOUT.truncate 0 ; STDOUT.rewind }
To reproduce see https://gist.github.com/1564418
No pid-file is created on startup. I guess line 24 should be:
File.open(pid, "w") { |f| f.write(Process.pid.to_s) } if pid
code:
require 'forever'
RAILS_ROOT = File.expand_path("..", File.dirname(__FILE__))
Forever.run :fork => true do
before :each do
require RAILS_ROOT + '/config/boot' # here the rails/padrino environment
end
every 2.seconds do
p 'hello world'
end
end
will appear the errors:
WARN: Unresolved specs during Gem::Specification.reset:
thor (>= 0.15.0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
"hello world"
Am I missing something?
the code:
#!/usr/bin/env ruby
require 'forever'
Forever.run do
on_ready do
puts "foop"
sleep 1
end
end
the result:
[~/tmp]$ ./test.rb
=> Found pid 34109...
=> Killing process 34109...
=> No such process
=> Process demonized with pid 34589
/Users/daniel/.rvm/gems/ruby-1.9.2-p180/gems/forever-0.0.8/lib/forever/base.rb:27:in `block in initialize': undefined method `sync=' for "/dev/null":String (NoMethodError)
from /Users/daniel/.rvm/gems/ruby-1.9.2-p180/gems/forever-0.0.8/lib/forever/base.rb:18:in `fork'
from /Users/daniel/.rvm/gems/ruby-1.9.2-p180/gems/forever-0.0.8/lib/forever/base.rb:18:in `initialize'
from /Users/daniel/.rvm/gems/ruby-1.9.2-p180/gems/forever-0.0.8/lib/forever.rb:10:in `new'
from /Users/daniel/.rvm/gems/ruby-1.9.2-p180/gems/forever-0.0.8/lib/forever.rb:10:in `run'
from ./test.rb:4:in `<main>'
[daniel@naruto]--(22:50:26)
I use forever js to run my node.js apps in the background as i dev them. I was hoping to use this for the same thing. Can you show an example of how you'd use this to run a rails webrick server (ideally with rails server -b 0.0.0.0).
Everytime i try to run the script i get the following error:
$ ./foreverb_test.rb
/Users/Leandro/.rvm/gems/ruby-1.9.2-p180/gems/foreverb-0.2.6/lib/forever/base.rb:219:in `write_config!': undefined method `load_file' for YAML:Module (NoMethodError)
from /Users/Leandro/.rvm/gems/ruby-1.9.2-p180/gems/foreverb-0.2.6/lib/forever/base.rb:17:in `initialize'
from /Users/Leandro/.rvm/gems/ruby-1.9.2-p180/gems/foreverb-0.2.6/lib/forever.rb:20:in `new'
from /Users/Leandro/.rvm/gems/ruby-1.9.2-p180/gems/foreverb-0.2.6/lib/forever.rb:20:in `run'
from ./foreverb_test.rb:4:in `<main>'
Here is the script code:
#!/usr/bin/env ruby
require 'forever'
Forever.run do
sleep 5
end
Can you push a version which includes lib?
forever-0.1.4$ pwd
/Users/philc/.rvm/gems/ruby-1.8.7-p334@default/gems/forever-0.1.4
forever-0.1.4$ find .
.
./bin
./bin/forever
./forever.gemspec
./README.md
I am experimenting with this wonderful gem and tried to run the following code:
<...>
What did I do wrong?
Fun!
resolved, bundler issue
https://github.com/DAddYE/foreverb/blob/master/lib/forever/base.rb#L124
This code creates 2 threads for every pid watching every second. After couple of hours thread limit will be reached soon
I'm using foreverb to run continues updates. In version 0.2.6 I could setup my script as follows:
Forever.run
on_ready do
while true
do_some_action
end
end
end
In the latest version I get a no jobs assigned exception. I've worked around it by adding the following:
every 100.days do
puts 'log this'
end
to make sure the jobs array receives a job. It's not really a bug per say, but it feel really dirty to set it up this way.
I had to switch to mri-2.1.1, since whenever I run a script based to foreverb, it dies raising the following stack trace:
[miyuki] Pid not found, process seems doesn't exist!
[miyuki] Process daemonized with pid 44416 with thread and Forever v.0.3.2
/Users/giovanni/.rvm/gems/ruby-head/gems/foreverb-0.3.2/lib/forever/base.rb:76:in `trap': Invalid argument - SIGKILL (Errno::EINVAL)
from /Users/giovanni/.rvm/gems/ruby-head/gems/foreverb-0.3.2/lib/forever/base.rb:76:in `block (2 levels) in initialize'
from /Users/giovanni/.rvm/gems/ruby-head/gems/foreverb-0.3.2/lib/forever/base.rb:76:in `each'
from /Users/giovanni/.rvm/gems/ruby-head/gems/foreverb-0.3.2/lib/forever/base.rb:76:in `block in initialize'
from /Users/giovanni/.rvm/gems/ruby-head/gems/foreverb-0.3.2/lib/forever/base.rb:349:in `fork'
from /Users/giovanni/.rvm/gems/ruby-head/gems/foreverb-0.3.2/lib/forever/base.rb:349:in `maybe_fork'
from /Users/giovanni/.rvm/gems/ruby-head/gems/foreverb-0.3.2/lib/forever/base.rb:69:in `initialize'
from /Users/giovanni/.rvm/gems/ruby-head/gems/foreverb-0.3.2/lib/forever.rb:18:in `new'
from /Users/giovanni/.rvm/gems/ruby-head/gems/foreverb-0.3.2/lib/forever.rb:18:in `run'
from /Users/giovanni/.rvm/gems/ruby-head/gems/miyuki-0.5.1/bin/miyuki:26:in `<top (required)>'
from /Users/giovanni/.rvm/gems/ruby-head/bin/miyuki:23:in `load'
from /Users/giovanni/.rvm/gems/ruby-head/bin/miyuki:23:in `<main>'
from /Users/giovanni/.rvm/gems/ruby-head/bin/ruby_executable_hooks:15:in `eval'
from /Users/giovanni/.rvm/gems/ruby-head/bin/ruby_executable_hooks:15:in `<main>'
Tests pass though.
bin/foreverb list
/u/apps/gsms/shared/bundle/ruby/1.9.1/gems/foreverb-0.3.0.f/bin/foreverb:22:in `read': can't convert nil into String (TypeError)
from /u/apps/gsms/shared/bundle/ruby/1.9.1/gems/foreverb-0.3.0.f/bin/foreverb:22:in `block in list'
from /u/apps/gsms/shared/bundle/ruby/1.9.1/gems/foreverb-0.3.0.f/bin/foreverb:20:in `each'
from /u/apps/gsms/shared/bundle/ruby/1.9.1/gems/foreverb-0.3.0.f/bin/foreverb:20:in `list'
from /u/apps/gsms/shared/bundle/ruby/1.9.1/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
from /u/apps/gsms/shared/bundle/ruby/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
from /u/apps/gsms/shared/bundle/ruby/1.9.1/gems/thor-0.14.6/lib/thor.rb:263:in `dispatch'
from /u/apps/gsms/shared/bundle/ruby/1.9.1/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'
from /u/apps/gsms/shared/bundle/ruby/1.9.1/gems/foreverb-0.3.0.f/bin/foreverb:170:in `<top (required)>'
from bin/foreverb:16:in `load'
from bin/foreverb:16:in `<main>'
Ubuntu Server 11.10
in lib/forever/base.rb class Base is ducplicated twice.
Since Ruby has open classes, last definition of methods win.
Perhaps there was a merge error?
Bundler could not find compatible versions for gem "thor":
In Gemfile:
foreverb (>= 0) x86-mingw32 depends on
thor (~> 0.14.6) x86-mingw32
padrino (= 0.10.7) x86-mingw32 depends on
thor (0.15.2)
How can this be fixed?
When running foreverb list
I'm been getting the following error:
Your config is empty, so no deamons was found.
I haven't been able to find any details on the ~/.foreverb
file format. Is it documented anywhere?
I can not load the environment and have access to models for example, I tried require '/config/boot', require_relative, require 'bundler/setup', does anyone know WHAT could it be?
Is there a way to run the daemon in live mode with log output going to stdout instead of to the log file? That would be much easier to manage than start + tail.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.