How to Send RubyMine Notifications to Growl/NotifyOSD? - notifications

I want just send command-line notifications (like "notify-send 'done' ") after some long rake tasks starting from Rubymine. Maybe I need some wrapper for rake? Thanks for help!

I don't know about RubyMine but this should do in Terminal:
rake db:setup && growlnotify -m 'Finished DB setup'

Add terminal-notifier gem to Gemfile
Add few lines to Project/bin/rake file: https://gist.github.com/skydan/f333cd1fc2900f4b4ed7

Related

how to run rake task in background in rails

This is my command
bundle exec rake resque:work QUEUE="*" --trace
I want to run this command on my server as a background process.
please help me.
A method I often use is:
nohup bundle exec rake resque:work QUEUE="*" --trace > rake.out 2>&1 &
This will keep the task running even if you exit your shell. Then if I want to just observe trace output live, I do:
tail -f rake.out
And you can examine rake.out at any time.
If you need to kill it before completion, you can find it with ps and kill the pid.
Just in case somebody finds this 4 years later, bundle has an elegant way of doing this now. For example if you want to run sidekiq in the background you can do:
bundle exec sidekiq -e production -d -L ./log/sidekiq.log
The -d daemonizes to run in the background, but you will also need to use the -L to provide a logfile, else bundler will refuse to run your command in the background (deamonize).
Tested with bundler version 1.15.4
Update Oct 2019.
While the command still works in general, the specific command above will no longer work for sidekiq 6.0+, you'll need to use Upstart or Systemd if you use Linux: https://github.com/mperham/sidekiq/wiki/Deployment#running-your-own-process

apn_sender gem daemon not running

Im using apn_sender for rails 3 and i have been able to install the gem and get it working just fine by using
rake apn:sender
I have tried to get it started in production mode on a ubuntu box by starting the daemon and it does not seem to work. When i type
script/apn_sender --environment=production --verbose start
I dont see anything. No log present.
when i try to type
script/apn_sender status
It returns with
apn_sender: no instances running
Just trying to understand why it is not running.
i just solved this problem. Try to create a file called 'script' in generators/apn_sender/templates . .
Put this in your script file
# !/usr/bin/env ruby
# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
require 'rubygems'
require 'apn'
require 'apn/sender_daemon'
APN::SenderDaemon.new(ARGV).daemonize
bash 'rails g apn_sender' in your terminal and will create 'script/apn_server' with same content as above
After that bash this code
./script/apn_server --environment=production --verbose start
it will create log/apn_sender.log . Try running
APN.notify('token',{:alert => '#' , :badge => 1})
or else in rails c to confirm if it works or not , and of course
rake apn:sender
Hope it will help :)
EDIT
You have to install redis and configure

Rails 3 - Whenever gem error: /usr/bin/env: ruby: No such file or directory

When using the 'whenever gem', I get an error in the log:
/usr/bin/env: ruby: No such file or directory
It works when I run the job manually. I've installed everything with RVM.
I've used the which command to find where my Ruby installation is, and I get:
kevin#lovely:/opt/personal$ which ruby
/home/kevin/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
and I've checked my $PATH variable, where it returns:
kevin#lovely:/opt/personal$ echo $PATH
/home/kevin/.rvm/gems/ruby-1.9.2-p290/bin:/home/kevin/.rvm/gems/ruby-1.9.2-p290#global/bin:/home/kevin/.rvm/rubies/ruby-1.9.2-p290/bin:/home/kevin/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
I believe this should be set up right, but I'm probably wrong since it doesn't work. Can anyone point me in the right direction?
If you're interested, this is what my whenever crontab output is:
# Begin Whenever generated tasks for: rss
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /opt/personal && script/rails runner -e development '\''FeedEntry.update_from_feed("http://lovely/blog/feed/")'\'' >> /opt/personal/log/feedzirra.log 2>&1'
You're probably long past this issue but for future reference:
I had a similar problem only I was getting
/usr/bin/env: ruby: No such file or directory
It turned out the first line of the file script\rails was #!/usr/bin/env ruby1.9.1, which tells the system to invoke it with ruby1.9.1 as explained here. But it should have been #!/usr/bin/env ruby1.9.3 since that was the version I had installed.
Hope this helps someone in the future :)
My issue was that ruby is in /usr/local/bin which is not in the path of a headless bash. So I just made my rake task line in schedule.rb:
job_type :rake, "cd :path && PATH=/usr/local/bin:$PATH RAILS_ENV=:environment bundle exec rake :task :output"
I am successfully using whenever with RVM and bundler in production. Here are the relevant pieces of my capistrano setup that may help you:
# rvm and bundler integration
require 'rvm/capistrano'
require 'bundler/capistrano'
# RVM environment
set :rvm_ruby_string, "ruby-1.9.2#mygemset"
# crontab
set :whenever_roles, :cron
set :whenever_command, "bundle exec whenever"
set :whenever_environment, defer { stage }
require 'whenever/capistrano'
The :whenever_environment setting is because I am using a multi-stage deployment setup. You can ignore that or set it to a string that matches your setup if needed.
Most of this information can be found at the whenever github page under the "Capistrano integration" and "RVM Integration" section headers in the README.
I hope that helps.
I solved the problem about the same as Duke. Except I figure out that $PATH variable is not working for me.
sys_path = '/home/[user]/.rbenv/versions/[ruby_version]/bin'
job_type :runner, "cd :path && PATH=#{sys_path} bin/rails runner -e :environment ':task' :output"
job_type :rake, "cd :path && PATH=#{sys_path} :environment_variable=:environment bin/bundle exec rake :task --silent :output"
If none of these worked for you, try:
gem install rails
This did the job for me, hope it helps!

jruby pass jvm arguments to rake task

How do i pass jvm arguments like Xmx to a rake task in jruby?
Am using rvm and running the rake task "rake db:migrate".
Thanks!
Rather that put the entire path, if jruby is already the Ruby you're using (for example, with rvm) such that just typing rake would be using jruby, you can use a double dash to send the arguments to the jvm.
Examples:
bundle exec rake -- -J-Xmx1024m (if you're using bundler)
rake -- -J-Xmx1024m
Found it!
jruby -J-Xmx2048m -S /home/prats/.rvm/gems/jruby-1.6.1#myapp/bin/rake db:migrate

How to add 'rake test' to project

When I ran rake -T, I discovered rake test was missing. What do I need to do to get this task in there? Specifically, I want to run rake test:benchmark but that doesn't seem to be loaded. For example...
$rake test:benchmark
rake aborted!
Don't know how to build task 'test:benchmark'
My config/application.rb file was missing this line:
require 'rails/all'
You only need:
require "rails/test_unit/railtie"
in your config/application.rb