Puma 2.9.2 and rufus-scheduler 3.0.3 incompatibility - puma

I´m using Rufus Scheduler 3.0.3 in a Ruby on Rails 4.1.4 web app and it´s working great with Unicorn. I moved to Puma and it´s great but I have realized Rufus is not working with Puma (daemonized).
I have read this issue #183 (comment) https://github.com/puma/puma/issues/183#issuecomment-59386038 that is closed for an earlier version, but it´s still not working and not clear to me if there is already a fix for it.
I don´t know if there is a workaround in the meantime.
UPDATE: There are not much logs to display, my rufus scheduler tasks are working when running with Unicorn, but If I change the server to Puma, it doesn´t run any automated task on my laptop. Even there is not any log to show.
I just add my current Rufus scheduler file:
task_scheduler.rb:
begin
require 'rufus-scheduler'
scheduler = Rufus::Scheduler.new
#Secretary responsible for executing events every 60 seconds.
scheduler.every '60s' do
Secretary.executeEvents
end
# Statistics (Owner) calculation every 1 day.
scheduler.every '24h' do
StatisticsCalculator.updateOwnerStatistics
end
end
Am I missing any configuration?
On the Puma side, I just have this config file config/puma/development.rb with only this:
stdout_redirect 'log/puma.stdout.log', 'log/puma.stderr.log', true
I don´t set up any workers, etc...

No, it works.
I packaged this sample project for you:
https://github.com/jmettraux/for_rober
Rufus-scheduler 3.0.3 schedules just fine with Puma 2.9.2 (Ruby 1.9.3 on Debian GNU/Linux).
Thanks for not blaming other people's work without facts.
If there really is an issue, I suggest you go and read http://www.chiark.greenend.org.uk/~sgtatham/bugs.html, then read it again, three times. It's most surely available in your native language. Then, if you really think rufus-scheduler is the culprit, go and open a detailed issue report at https://github.com/jmettraux/rufus-scheduler/issues Beware posting crappy "it doesn't work" material, it'll earn you only negative reactions.
UPDATE:
I strongly suggest you clone my mini-project on your machine and try it, then report the results here in the comments. The details are in the README.md of the project.
UPDATE:
Roberto is trying to get this issue solved in parallel, directly at https://github.com/puma/puma/issues/607

Finally, it looks there was an small issue. It has been kindly fixed by the Puma guys.
Please, see:
https://github.com/puma/puma/issues/607

Related

Zeus not reloading code changes in model files in Rails

I've recently discovered Zeus and it's fantastic really speeds up my feedback loop when developing it's just that when I'm making changes to my model like adding a new method Zeus doesn't restart and the new method isn't loaded.
I'm not sure where to start debugging but I'm using Rails 4.0.2, ruby 2.0.0p353 and Rspec + Capybara for testing.
Anyone have any ideas or help that would be fantastic.
Thanks a lot
If you are using unicorn this could be your problem. Try using thin instead
Zeus:
Reloads models correctly when modifying callbacks and scopes, which
is not always the case for servers with hot-reload, such as Unicorn.
It also reloads views when writing integration specs.(source)
You may also need to reconfigure foreman. Check this thread for information on foreman support with Zeus: https://github.com/burke/zeus/issues/92

Ruby on Rails, callback, run a method later

I need somekind of a callback for a function to be caled in 5 min after the create-method.
My situation:
The user logs in in my web-page, uploads some files (create-method is invoked), in 5 min should the files be on their way to be analyzed(in 5 min it should call the method, which just take the whole folder, where the files are stored and analysis it). That is why such things like typing rake jobs:work or using gem daemons and typing "RAILS_ENV=production script/delayed_job start" in the command line does not suit me.
I want to start my apllication as usual with rails s, log in, upload the files and it should work automatically that the files are analyzed.
As I understood once the jobs started they will continue run? I do not need this. I need just some methods run in 5 min after create method.
All this stuff with gem 'delayed_job_active_record' to qeue the jobs and daemons to start the workers seem too complicted for such an easy task.
So, is it possible using gem 'delayed_job_active_record' and gem daemons to start my application with rails s and everythings will be done automatically in background without me stopping an application and typing things in the commanline to run the delayed jobs?
Or is it possible to do without all thise complicated stuff?
I have already asked about delayed_jobs here and here.
Many thanks in advance.
Here is a post where it is described how to set up scheduling with delayedjob
Update 2015-07-06: link's broken and I can't find a cached version - see update below
If you can, I recommend looking into sidekiq which is a great message queue and even has built in scheduling. It does use redis though, so unless you already have redis deployed it will be a tiny bit of work.
Update
Here is a gist with a simple solution to scheduled and recurring jobs with delayedjob

How do you spawn an EventMachine "inside" a Rails app?

I've got a Rails application, and am looking to add some sort of WebSocket support to it. From various googling, it appears that the best Ruby based WebSocket solution is em-websocket running on EventMachine.
I was wondering if there was a way to "integrate" an EventMachine reactor into Rails? Where do I put the initialization code? Is this the proper way to accomplish this?
I've seen this example that falls back on Sinatra to do an EventMachine GET request, but that isn't quite what I'm looking for.
Any help is appreciated.
You cannot run the Eventmachine engine inside of Rails itself as it is a persistent run loop that would block one of your Rails processes permanently. What is usually done is there's a side-process that uses Eventmachine and Rails communicates with it through sockets to send notifications.
Juggernaut serves as an example of this kind of thing where it implements a Websocket client and a Rails hook to send notifications to it. The project has since deprecated the Ruby version in favor of a JavaScript Node.js version but this still serves as a very thorough example of how Eventmachine can be used.
If you run rails application in a thin server (bundle exec thin start) thin server run EventMachine for you and then your rails application can execute EM code wherever you need.
By example:
A library o initializer with that code:
EM.next_tick do
EM.add_periodic_timer(20) do
puts 'from Event Machine in rails code'
end
end
not blocks rails processes application.
Don't know if this is what you are after. But if you would like to do provide some kind of socket-messaging system.
Have a look at Faye. It provides message servers for Node.js and Rack. There is also a rails cast for this by Ryan Bates which should simplify the implementation.
Hope that helps.
I spent a considerable amount of time looking into this. EventMachine need to run as a thread in your rails install (unless you are using Thin,) and there are some special considerations for Passenger. I wrote our implementation up here: http://www.hiringthing.com/2011/11/04/eventmachine-with-rails.html
UPDATE
We pulled this configuration out into a gem called Momentarily. Source is here https://github.com/eatenbyagrue/momentarily
I'd try using em-synchrony to start a reactor in a fiber. In a rails app you can probably start it in an initializer since it sounds like you just want to leave the reactor running to respond to websocket requests. As suggested by the other answers I think you want to either setup socket communication with your reactor or use one of the asynchronous clients to a data store which both your reactor and rails code can read from and write to to exchange data.
Some of my coworkers put together some examples of starting EM reactors on demand in ruby code to run their tests within EventMachine. I'd try using that as a possible example; raking and testing with eventmachine
I'd consider looking into Cramp. It's an async framework built on top of EventMachine, and it supports Thin server:
Rack Middlewares support + Rainbows! and Thin web servers
You probably shouldn't use EM any more if you can help it, it seems to no longer be maintained - if you encounter a bug - you're on your own.
Most of the answers above don't work in JRuby due to https://github.com/eventmachine/eventmachine/issues/479 - namely the pattern:
Thread.new{ EM.run }
used by EM::Synchrony and various answers found around the internet (such as EventMachine and Ruby Threads - what's really going on here?) are broken under JRuby eventmachine implementation (fibers are threads in jruby and there's currently no roadmap on when this will change).
JRuby messaging options would be
deploy with TorqueBox (which comes bundled with HornetQ), http://torquebox.org/news/2011/08/15/websockets-stomp-and-torquebox/, impressive and enterprisey but not really elegant unless you're coming from a Java background
newer versions of Faye should work with JRuby, Faye in jruby on rails
note for the future, keep an eye on the celluloid community, some interesting distributed solutions are coming from there https://github.com/celluloid/reel/wiki/WebSockets, https://github.com/celluloid/dcell
?
I had same problem and found solution. First, put your code in lib dir (for example /lib/listener/init.rb) and create one class method that run EM, for example Listener.run.
#!/usr/bin/env ruby
require File.expand_path('../../config/environment', File.dirname(__FILE__))
class Listener
def self.run
# your code here
# you can access your models too
end
end
After that I used dante gem. Create /init/listener file. The code may be like that:
#!/usr/bin/env ruby
require File.expand_path('../../lib/listener/init.rb', __FILE__)
log_file = File.expand_path('../../log/listener.stdout.log', __FILE__)
pid_file = File.expand_path('../../tmp/listener.pid', __FILE__)
listener = Dante::Runner.new('listener')
if ARGV[0] === 'start'
listener.execute(daemonize: true,
pid_path: pid_file,
log_path: log_file) { Listener.run }
elsif ARGV[0] === 'restart'
listener.execute(daemonize: true,
restart: true,
pid_path: pid_file,
log_path: log_file) { Listener.run }
elsif ARGV[0] === 'stop'
listener.execute(kill: true, pid_path: pid_file)
end
Now you can run you code like that: ./bin/listener start, ./bin/listener restart, ./bin/listener stop
You can use god for monitoring your listener is running. But make sure you're using same pid file (/tmp/listener.pid).

Autoscaling workers for delayed_job in Rails 3

I've been using collectiveidea's fork of delayed_job as a gem in my Rails 3 app, and it's working fine. I'm now looking for a solution to autoscale workers, specifically for Heroku. I've given pedro's fork a try but since it's written for Rails 2, using it throws lots of errors and warnings about deprecated methods and I haven't been able to get it to work successfully.
Is there a working solution for Rails 3 delayed_job with autoscaling workers?
You might want to take a look at workless, it's one of the only Rails3 worker autoscalers I've seen at this point.
Specifically for heroku, check out "HireFire - The Heroku Worker Manager" and hirefireapp service:
https://github.com/meskyanichi/hirefire - open source
http://hirefireapp.com/ - service in public beta now
I've started working on a gem called Komodo to perform that very same task for un upcoming project at work. However, since we've only just started on the project, the gem is still very, very early - and untested.
I should see some consistent updating over the next couple of weeks though - would certainly appreciate any feedback or contributions! :)

Rails 5.1.7 Server Hangs On First Request

We are trying to update a Rails Server to release 5.1.
Server starts fine; but on the first request, goes completely dead; and has to be killed with signal 9.
Doesn't matter if its Puma or Webrick.
Doesn't matter if its 5.1.0 or 5.1.7
Doesn't matter if its development or production mode.
Eventually I saw the process size was 90GB and growing!
I've tried rbtrace, but struggled to get anything meaningful out of it.
I'm on osx, so strace isn't available, and I've struggled to get dtrace or dtruss to work, or produce anything meaningful.
So looking for a way to get this rails server to tell me what it's problem is....
Let me know what additional information is salient.
After quite a long process, I found a solution that didn't so much find the source of the issue, but provided a process to work around it.
First off, I used
rails app:update
And accepted all of the overwrites. Then using git, I walked through all of the removed code from my config file and returned just the required sections [like config/routes.rb, and ActionMailer config, for example].
Application then started right up, no issue.
This also led me to
http://railsdiff.org/5.0.7.2/5.1.0
Which is pretty critical for Rails upgrading. This is well worth consuming:
https://github.com/rails/rails/issues/31377#issuecomment-350422347

Resources