I tried to make a script that would execute several external binaries to perform some tasks. Each binary was executed from a different thread, but the thing is, it didn't work ( because of the implementation of Ruby's threads in 1.8.6 ).
Is there a different way I could do this, or do I have to go with Ruby 1.9 ?
Have you try Ruby Daemons? I have about 15 external application running simultaneously with RoR by implement it. (http://daemons.rubyforge.org/)
Basically, you extract your thread code to another ruby file. say my_external_call.rb. then, create a daemon control
require 'daemons'
Daemons.run('my_external_call.rb')
execute it by 'ruby control.rb start | stop | status'
Related
I'm writing a node module to be open sourced and there's a dependency on some Ruby code (see Can I include a Ruby Gem in a Node.js project? for details). I made a Ruby project that requires some gems and all of that works well. In my node_module, I want to interface it via exec to the Ruby code.
But now there's Ruby dependencies as well. So can I somehow specify the Ruby version, and the gemset required to run my node package?
Ambiguous question perhaps. I can clarify if anything is unclear.
I don't think you can/should specify the Ruby version to use when executing your code. That should be up the library consumer so choose. Since you want to execute your code with exec, the library consumer will have the added responsbility of making ruby accessible to the node process. How that happens is not up to you as the library developer.
As for dependencies/gemsets, just use bundler.
Maybe you could do something like this - without more information it's hard to say.
On the ruby side, build your gem to do whatever it needs to do and then add a rake task to it. How you build this rake task is obviously up to the demands of the project and how it will be used, but it will provide a way for you to interface from the outside.
In the 'middle' build a bash script that includes RVM - this way you can require a specific gemset/do specifc things before running the rake task. Another benefit is that if you want to change the gemset or other implementation details, you just change the bash script.
On the node side, call the bash script. More info on that in this answer.
I am using this gem:
win32-service (0.7.2 x86-mingw32)
The gem has a demo_daemon.rb and a demo_daemon_ctl.rb in the example directory.
I have tried to run the example as a service using both ruby 1.8.7 and 1.9.3 and I get the error below.
The daemon tries to write to a log file, but it never reaches a point where the log file gets written. Even if I put a log write on startup of the script nothing gets written.
My machine is 64 bit.
Any ideas on what I can try or what could be the issue?
C:/Ruby193/lib/ruby/gems/1.9.1/gems/win32-service-0.7.2-x86-mingw32/lib/win32/se
rvice.rb:760:in `start': The service did not respond to the start or control req
uest in a timely fashion. (Win32::Service::Error)
from demo_daemon_ctl.rb:75:in `<main>'
I think you need use a service wrapper such as srvany . Here is the Microsoft's guide. Use full path for both ruby and the script in the "Application" parameter. And if something goes wrong under 64bit system, just put the srvany.exe in both windows/system32 and windows/sysWow64 folder.
I have placed all my specs in specs/*.rb.
However, when I run Minitest with ruby spec/**/*_spec.rb, only one file is run.
What gives?
This is not minitest specific, but Ruby. You are effectively running a ruby program which knows nothing about the program being run.
Ruby does not support running multiple files at once afaik, so if you want to get a similar result you could try something like:
for file in spec/**/*_spec.rb; do ruby $file; done
UPDATE: for what you want you should probably create a Rake task as described here
You can use the testrbl third party gem to run multiple Minitest files on the command line. You could also use the mtest bin from maxitest extensions.
Using a for loop in bash will incur overhead of loading your application/library for every test you pass it. If you have just ten tests, and you're testing a Rails app that takes 5 seconds to boot, that's over a minute of totally unnecessary load time.
Reading the documentation here, https://devcenter.heroku.com/articles/scheduler, I see how to schedule tasks with rails. But I was wondering how to schedule tasks with regular ruby?
What do I have to put in the task field to have my ruby script run?
You should be able to add a Rakefile to your regular ruby app, and run rake task_name via the scheduler.
Not sure if once upon a time you had to use rake, but no more. Just use ruby directly:
ruby path/to/yourfile.rb arg1 arg2
I've got a Ruby project started with NetBeans, so the Rake file has been generated. Is there a way that I can run the project over the command line?
It runs fine when I use F6 through NetBeans, as does my automated test suite with Alt+F6. I'm essentially looking for something like...
$ rake run
Does this exist?
The goal of ruby programming is (generally) to either write a web application, or write a program that can be run from the command line.
For a web application a rake run option might be worthwhile, but really the most common web applicaition framework is Rails, and for rails, you can just run a dedicated webserver running your web app with script/server.
For a commandline program, just run whichever ruby file you have intended as the main file (the one with the code that runs at startup). Ruby doesn't have any of the difficulties that Java does (e.g. having a jar file with the right Main-class attribute, and getting the classpath right, etc...). So you don't really need a rake run target, because there's no complexity that needs to be hidden in the rakefile.
Although Ken's right, you can certainly make a rake task to run your program. In lib/tasks/project.rake:
namespace :project do
task :run do
call_your_code()
end
end
and then rake project:run will do what you want.