I am using rails.vim plugin which is pretty awesome. However, I fail to see how could I test all the specs in one command. Right now I need to open a particular spec and do :Rake and that just tests the current opened spec. However, how could I test all the specs? Which command?
Thanks
Have you tried pairing a rake task with a ViM leader mapping?
In your Rakefile, you could set up something like this:
desc 'Continuous integration task'
task :ci do
['rspec',
'cucumber -f progress',
'rake konacha:run'].each do |cmd|
system("bundle exec #{cmd}")
raise "#{cmd} failed!" unless $?.exitstatus == 0
end
end
Then you can setup a leader command in ViM to execute your ci rake task:
nnoremap <leader>T :w\|:!bundle exec rake ci<CR>
Then when you execute <leader> T in normal mode, ViM will shell out and run bundle exec rake ci.
I use tmux, so I prefer the following leader mapping which runs the rake task in a bottom pane:
nnoremap <leader>T :w\|:silent !tmux send-keys -t bottom C-u 'bundle exec rake ci' C-m <CR>\|:redraw!<CR>
Related
I have been using resque for background processing, No my problem with code is :
- when I start rake task as "rake resque:work QUEUE=''" as per ryan bates episode no. 271. in remote server the code inside worker class for file maipulation works properly without any filepath issues and I/O errors.
- when i start rake task as "rake resque:work QUEUE='' BACKGROUND=yes" now, the code inside worker class gives "failed:Errno::EIO: Input/output error # io_write - >" error.
Now my question is I want to start the resque queue above rake command only one time and why second point giving error is this issue with filepaths if so then why it runs smoothly as mention in point first.
You can use god to manage your background process. Or nohup can be your solution too as below:
$ nohup bundle exec rake resque:work QUEUE=queue_name PIDFILE=tmp/pids/resque_worker_QUEUE.pid & >> log/resque_worker_QUEUE.log 2>&1
and even this command worked for me:
PIDFILE=./resque.pid BACKGROUND=yes QUEUE="*" rake resque:work >> worker1.log &
Hope that will help you too.
I have rake task which runs in every 5 mins with crontab. This rake task has to start one long running background process which creates a file as per task inputs.
For some reason long process is not running . I am using Backticks to run the command.
Any idea ?
rake task file
require 'json'
namespace :scrapper do
path = '/home/ubuntu/users'
def lockfile
Rails.root.join('tmp', 'pids', 'leads_task.lock')
end
def running!
`touch #{lockfile}`
end
def done!
`rm #{lockfile}`
end
def running?
File.exists?(lockfile)
end
task :get_profile => :environment do
unless running?
running!
user = User.last
`/usr/local/bin/casperjs #{path}/scrapper.coffee #{user.id}`
done!
end
end
end
cron syntax looks like this
*/5 * * * * /bin/bash -l -c 'cd /home/ubuntu/UserProfile && RAILS_ENV=staging bundle exec rake scrapper:get_profile --silent >> /home/ubuntu/UserProfile/scrapper_cron.output 2>&1'
few wried things
The cron job is running, i see scrapper_cron.out file get created when i delete it.
The rake task is running when i type it in shell and execute it.
I have rake timeout gem in my app which is giving timeout error to the rake task. Since, the cron command includes silent flag it is suppressing the error .
I'm trying to get whenever to work with sinatra. When I run the whenever command, I get the generated cron tab. But the problem is, that in my sinatra app, I don't have a script/runner file, which is present in Rails.
How do I get this runner, or is there a whenever command to generate one?
thx!
You can use a rake task in place of script/runner. The Whenever gem supports defining the job via a rake task (and more in fact)
Sample:
# config/schedule.rb
every 3.hours do
rake "destroy_all"
end
and in your Rakefile: (for lack of good examples)
task :destroy_all do
puts "Do not do this"
# sh "rm -rf ."
end
I use crontab to invoke rake task at some time for example: every 3 hour
I want to ensure that when crontab ready to execute the rake task
it can check the rake task is running. if it is so don't execute.
how to do this. thanks.
I'll leave this here because I think it's useful:
task :my_task do
pid_file = '/tmp/my_task.pid'
raise 'pid file exists!' if File.exists? pid_file
File.open(pid_file, 'w'){|f| f.puts Process.pid}
begin
# execute code here
ensure
File.delete pid_file
end
end
You could use a lock file for this. When the task runs, try to grab the lock and run the rake task if you get the lock. If you don't get the lock, then don't run rake; you might want to log an error or warning somewhere too or you can end up with your rake task not doing anything for weeks or months before you know about it. When rake exits, unlock the lock file.
Something like RAA might help but I haven't used it so maybe not.
You could also use a PID file. You'd have a file somewhere that holds the rake processes process ID. Before starting rake, you read the PID from that file and see if the process is running; if it isn't then start up rake and write its PID to the PID file. When rake exists, delete the PID file. You'd want to combine this with locking on the PID file if you want to be really strict but this depends on your particular situation.
All you need is a gem named pidfile.
Add this to your Gemfile:
gem 'pidfile', '>= 0.3.0'
And the task could be:
desc "my task"
task :my_task do |t|
PidFile.new(piddir: "/var/lock", pidfile: "#{t.name}.pid")
# do something
end
I need to execute a rake task in a windows machine and unfortunately to do so I have to open a shell. How can I close it once the task has been completed?
system('start rake db:MyTask')
Thanks,.
maybe something like
system('start rubyw -S rake db:MyTask')
are you running this from the "run" box? Why is a window popping up?