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
13
votes
1 answer

Rake task w/ splat arguments

I'm attempting to create a rake task that takes a required first argument, and then any number of additional arguments which I want to lump together into an array: rake course["COURSE NAME", 123, 456, 789] I've tried the following but…
Kyle Decot
  • 20,715
  • 39
  • 142
  • 263
12
votes
2 answers

How to include ActionMailer class in rake task?

I want to use ActionMailer in my rake task in order to send emails to people at a particular time. I have written a mailer class in app/mailers folder like this: class AlertsMailer < ActionMailer::Base default from: 'x@y.com' def…
Joy
  • 4,197
  • 14
  • 61
  • 131
12
votes
3 answers

Where to put helper functions for rake tasks and test files in Ruby on Rails?

In my Rails application I have a file sample_data.rb inside /lib/tasks as well as a bunch of test files inside my /spec directory. All these files often share common functionality such as: def random_address [Faker::Address.street_address,…
Tintin81
  • 9,821
  • 20
  • 85
  • 178
11
votes
3 answers

Testing a method defined in a rake task

I want to test a method defined in a rake task. rake file #lib/tasks/simple_task.rake namespace :xyz do task :simple_task => :environment do begin if task_needs_to_run? puts "Lets run this..." …
Garfield
  • 1,247
  • 4
  • 15
  • 33
10
votes
2 answers

Rails rake task fails just in production: "NoMethodError: private method `open' called for URI:Module"

I am coding a rake task which function is getting info from other webpage. To do that I use open-uri and nokogiri. I have tested in development and it does the job, but then I deploy to the production server and fails. This is the code: require…
Juanse Cora
  • 755
  • 9
  • 19
10
votes
3 answers

How to build task 'db:populate'

1 namespace :db do 2 desc "Fill database with sample videos" 3 task :populate => :environment do 4 require 'faker' 5 Rake::Task['db:reset'].invoke 6 100.times do |n| 7 headline = Faker::Lorem.sentence(3) 8 …
Teej
  • 12,764
  • 9
  • 72
  • 93
10
votes
1 answer

Rails: rake db:test:prepare Vs rake test:prepare

AS the guides, the command used to prepare test database is bundle exec rake db:test:prepare However, I have found that following command also works & created the test db for me. bundle exec rake test:prepare Wanted to know if this is a valid…
CuriousMind
  • 33,537
  • 28
  • 98
  • 137
9
votes
5 answers

rake check if already running

Is it possible somehow to execute rake task only if it is not running already, I want to use cron for executing some rake tasks but rake task shouldn't start if previous call is not finished Thanks
Fivell
  • 11,829
  • 3
  • 61
  • 99
9
votes
4 answers

Rake tasks for multiple databases with different schemas

I am working on a multi-database Rails 3 application. Each database has a different schema (and in production are located in different locations). I've set the app to talk to different databases like so: database.yml development: adapter: mysql2 …
Paul
  • 420
  • 4
  • 16
9
votes
4 answers

How to parse rake arguments with OptionParser

Reffering that answer I was trying to use OptionParser to parse rake arguments. I simplified example from there and I had to add two ARGV.shift to make it work. require 'optparse' namespace :user do |args| # Fix I hate to have here puts "ARGV:…
pawel7318
  • 3,383
  • 2
  • 28
  • 44
9
votes
2 answers

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.
manish nautiyal
  • 2,556
  • 3
  • 27
  • 34
9
votes
3 answers

How to get help on a specific rake task?

Is there a standard help command for individual rake tasks? rake -h displays the options for rake. rake -D describes the rake tasks. rake mytask runs mytask. Is there something like rake -h mytask that would describe mytask, and list its optional…
user1385729
  • 1,276
  • 1
  • 15
  • 19
9
votes
2 answers

Single step batch delete in Ruby on Rails

How to send such a query to database server from Rake task without removing record-by-record in "each" loop? delete from data where uuid in ( select uuid from data group by uuid, raw, recdate having count(*)>1 );
Paul
  • 25,812
  • 38
  • 124
  • 247
8
votes
2 answers

newbie: error message when 'rake -T'

I am using Ruby Enterprise Edition for my project. When I check all my rake task by run the command rake -T , I got the following error message: You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Using bundle exec may…
Mellon
  • 37,586
  • 78
  • 186
  • 264
8
votes
2 answers

How can I export database structure from the db into migration file?

Is there a way to export database structure in the database from the rails application? I believe there is a way to export Data from the db using rake. rake db:migrate will create tables from migration files. Is there a command that does opposite…
user482594
  • 16,878
  • 21
  • 72
  • 108
1
2
3
45 46