Questions tagged [rake-task]

Task is the basic unit of work in a Rakefile.

Tasks have associated actions (possibly more than one) and a list of prerequisites. When invoked, a task will first ensure that all of its prerequisites have an opportunity to run and then it will execute its own actions.

Tasks are not usually created directly using the new method, but rather use the file and task convenience methods.

689 questions
3
votes
1 answer

Rspec Rake Task: How to parse a parameter?

I have a rake task which generates a new User. Values of email, password and password_confirmation (confirm) needs to be typed in through the command line. This is my rake task code: namespace :db do namespace :setup do desc "Create Admin…
ChrisK
  • 99
  • 9
3
votes
0 answers

How do I import one set of rake tasks into another but inside a namespace?

I have three projects, I want to be able to import project B and C's rake files into project A rake file but each inside of it's own namespace: Now to the…
Justin Ohms
  • 3,334
  • 31
  • 45
3
votes
2 answers

rake aborted! ArgumentError: wrong number of arguments (2 for 0..1)

My rails task looks like this: desc 'Delete records older than 7 days' task :delete_old_records => :environment do Post.delete_all('created_at < ?', 7.days.ago) end I tried to execute the task using: rake delete_old_records --trace and…
mr i.o
  • 952
  • 2
  • 10
  • 20
3
votes
1 answer

Rakefile - access variable defined in a prerequisite

Is there some way to access a variable defined in a prerequisite? e.g. task :new_file do filename = 'foobar.txt' # in reality I ask the user for the filename File.write(filename, 'Some glorious content') end task :new_file! => [:new_file]…
mathematical.coffee
  • 55,977
  • 11
  • 154
  • 194
3
votes
2 answers

How do I use File.join with File::ALT_SEPARATOR?

I want to use File.join() for building paths in Ruby: File.Join("Dir1", "Dir2", "Dir3") Result is: Dir1/Dir2/Dir3 I want File.join() to uses File::ALT_SEPARATOR for doing this: Dir1\Dir2\Dir3 How do I do this?
A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128
3
votes
1 answer

How to catch rake task exit status in another rake task

Problem I have something like this: task :fail do exit 111 end task :run_fail_and_succeed do begin Rake::Task['knapsack:fail'].invoke rescue exit 0 end end I would like to run task :fail and handle it's exit status. Than exit with…
ciembor
  • 7,189
  • 13
  • 59
  • 100
3
votes
2 answers

How to seed test data in Rails not using seeds.rb?

I have seeds.rb populating my development database. And I know I can easily apply seeds.rb to my test database using: rake db:seed RAILS_ENV=test However, I want a different seeds.rb file to populate my test database. Maybe seeds_test.rb. This must…
at.
  • 50,922
  • 104
  • 292
  • 461
3
votes
1 answer

How to exit the rake task when running timeout?

I set a cron job to run a rake task. This task will do somethings, such as send a post request... If timeout, process cannot finished normally. How to set a timeout time, if this time is surpassed, then the rake task will exit.
pangpang
  • 8,581
  • 11
  • 60
  • 96
3
votes
2 answers

How to schedule whenever task based on a table column?

I am using whenever gem to run rake tasks. My code in schedule.rb is as follow. every 1.day, :at => '11:00 am' do rake "notifications:run_mailer" end Above code is executing the rake task on 11am of every day. Now i want to change this. I want…
Can Can
  • 3,644
  • 5
  • 32
  • 56
3
votes
1 answer

Ensure appended code to Rake task gets run no matter what

I have appended a my_checks method call to the rails db:migrate invocation. The code below works great as long as db:migrate does not throw an exception. However, if db:migrate does throw an exception, the my_checks method won't be executed. Is…
Reck
  • 7,966
  • 2
  • 20
  • 24
3
votes
2 answers

Rake task with multiple prerequisites generating multiple outputs

I have a method that depends on two files for input, and that produces two or more files as output. There is no one-to-one mapping between each input file and each output file - the method performs operations that combines the input data to produce…
Lars Haugseth
  • 14,721
  • 2
  • 45
  • 49
3
votes
1 answer

Simple pattern to export rake tasks defined in gem to the outside world upon installation

This question follows the "Make rake task from gem available everywhere?" for which I'm not fully satisfied with the Railties approach since it induces a dependency on Rails3 which seems to me overkilling compared to what I want. Also, I dislike…
Sebastien Varrette
  • 3,876
  • 1
  • 24
  • 21
3
votes
1 answer

Run a custom rake task on rails

I am trying to make a custom rake task, but I cannot seem to get it working. My code looks like this: namespace :demotask do desc "display the current environment of rake" task :current_environment => :environment do puts "You are running…
NinGen ShinRa
  • 651
  • 5
  • 16
3
votes
1 answer

Rails Custom Rake Task no method error

I am trying to set up a custom rake task for a Rails app that checks to see if your location is within a certain area with street cleaning restrictions. If it is, you can click a button "Remind Me" that will save the user id and restriction id to a…
mnicole
  • 53
  • 6
3
votes
0 answers

Getting "(LoadError) no such file to load -- ant/tasks/raketasks" while calling rake from ant

I want to execute rake task from within ant. My jruby is available as a zip file during build process and I'm extracting it during run time. My build.xml is something like below:
Keyur Shah
  • 81
  • 1
  • 6