How to setup Heroku Scheduler without Rails? - ruby

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

Related

run all selenium ruby webdriver scripts at a time.

Currently, I'm running each my Selenium Ruby Webdriver script (*.rb) on Ruby command prompt window with the syntax, ex: ruby test.rb. It works well.
However, I also have some other scripts and now I want to run all scripts once instead of calling ruby test1.rb, then wait for this script done, then continue to run: ruby test2.rb.....then, ruby test3.rb.....
Anybody please guide me a way to run all scripts I created at a time? Thanks so much.
You can use the rake gem, for this you need to create a file named rakefile.rb, and paste the below content:
task :default do
FileList['file*.rb'].each { |file| ruby file }
end
Now call rake in your terminal, you should be good.
What about making a feature file and running the entire feature?
Just create a ruby file like this:
require './Test1.rb'
require './Test2.rb'
Run it and see the result

Ruby Gem Testing Workflow

What is the standard for testing while creating ruby gem?
Do most people run something like guard, or write tests and trigger them manually from the command line?
In Ruby there isn't really a "standard", instead people usually use what works well for them. If you don't like things like guard and prefer to run the tests from the command line, run the tests from the command line.
When I'm coding I run my tests manually from the command-line, but I also have a cron job that will run the tests against the latest commits and email the results every night.

how to run a simple file on heroku

say I've got my rails app on github and am deploying the github repo on heroku.
I've got a situation where I have a simple text file with bunch of words (it is in my github repo). I want to insert these words (using a simple ruby program) into a database. Instead of using the tap command, is it possible in heroku to just run my simple ruby program and insert the words into the database...or maybe just show them on the terminal?
maybe confusing but basically I want to know how to run simple ruby script from heroku command line?
With cedar, you can run bash:
heroku run bash
Put your ruby script in a bin directory and git push it to Heroku. Now you can execute a shell command in the heroku console.
For example, if your Ruby script is bin/foo.rb, you can run the following command in the Heroku console:
`ruby bin/foo.rb`
Note the use of backticks.
Since you're talking about a Rails app on Heroku, how about using rails runner:
heroku run bundle exec rails runner ./path/to/script.rb -a <your-app>
Have a look at the RailsGuides for rails runner for more details.
Alternatively, turn that script into a rake task if runner is not your cup of tea (eg, for recurring tasks).
cd /path/to/my/local/repository
heroku console
require 'my_word_importing_script'
Failing that, try a simple Sinatra application as importer.rb?
require 'sinatra'
require 'sequel'
configure do
// connect to the database with sequel
end
get '/import/a-long-unguessable-url-fdsjklgfuiwfnjfkdsklfds' do
words = YAML.load(File.join(File.dirname(__FILE__), "my_list_of_words.yaml"))
words.each do |word|
// Your logic for inserting into the database with sequel
end
end
Hitting http://example.com/import/a-long-unguessable-url-fdsjklgfuiwfnjfkdsklfds in your browser would kick off the import. Handy for an external cron task.
You would also need a config.ru file in the repo:
require 'importer'
run Sinatra::Application
If you want to run arbitrary local Ruby files on Heroku, check out the blog post at
http://www.22ideastreet.com/debug/run-local-scripts-on-heroku
There are some things to watch out for (long run times, etc.) but it might be useful if you have a file that you haven't checked in that you want to test or run on a Heroku instance.

Is it possible to run a Ruby project via Rake?

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.

How can I execute binaries from Ruby threads and remain threaded?

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'

Resources