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
8
votes
5 answers

How to return some value from rake task

How can I return some value from a Rake task in ruby. Sample code: namespace tasks task task1: :environment do |task| log = "Running task" puts log log << "Done" return log # suggest how to do this end end I am…
Rajesh Paul
  • 6,793
  • 6
  • 40
  • 57
8
votes
8 answers

rake db:migrate is being aborted due to rake version difference

I am getting the error rake db:migrate --trace rake aborted! You have already activated rake 10.1.1, but your Gemfile requires rake 10.1.0. Using bundle exec may solve…
iang
  • 83
  • 1
  • 1
  • 3
8
votes
1 answer

What exactly does $:.unshift(File.expand_path("../../lib", __FILE__)) do?

There are a lot of threads on here about this already I know but none of the titles have this worded exactly like I did. I hope that we can clear this up a bit. $:.unshift(File.expand_path("../../lib", __FILE__)) You see something like this in a…
Douglas G. Allen
  • 2,203
  • 21
  • 20
8
votes
2 answers

bundle package fails when run inside rake task

My Environment Vanilla Ubuntu 12.10, no rvm or renv. > gem --version 1.8.23 > ruby --version ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] > bundle --version Bundler version 1.2.1 My problem I have a rake task to package my gems and…
Horacio
  • 2,727
  • 5
  • 26
  • 29
8
votes
2 answers

Rails creating a table without migration

I have a rails app that has a particular table where the data and even the structure is dynamically generated outside of rails and ruby. This is by design, it is a special table where the structure is self-contained from the rest of active record…
Gordon Potter
  • 5,802
  • 9
  • 42
  • 60
7
votes
2 answers

Rails 3.1: how to run an initializer only for the web app (rails server/unicorn/etc)

My webapp needs to encrypt its session data. What I setup is: config/initializers/encryptor.rb: require 'openssl' require 'myapp/encryptor' MyApp::Encryptor.config[ :random_key ] = OpenSSL::Random.random_bytes( 128…
sbutler
  • 617
  • 5
  • 10
7
votes
2 answers

How do I override rake tasks for a custom database adapter?

I've written a custom database adapter that works correctly and effectively when a rails server is running. I would now like to add the usual rake task definitions for creating, dropping and migrating the database. I would like to…
TCopple
  • 880
  • 7
  • 14
7
votes
1 answer

rails 3 built-in rake tasks, where are they located?

I can put my custom rake tasks in lib/tasks/, but where are the built-in ones (i.e. db:migrate, db:seed, etc) stored? I looked in: [INSTALLATION_DIRECTORY]/gems/rails-[VERSION]/lib/tasks but couldn't find that path. Maybe it matters that I'm using…
SooDesuNe
  • 9,880
  • 10
  • 57
  • 91
7
votes
3 answers

testing rake tasks with Rspec is not accepting arguments

I am trying to write a Rspec test for one of my rake task, according to this post by Stephen Hagemann. lib/tasks/retry.rake: namespace :retry do task :message, [:message_id] => [:environment] do |t, args| …
x6iae
  • 4,074
  • 3
  • 29
  • 50
7
votes
4 answers

Why is my rake task running twice in my test?

I have a rake task test that I setup following the only examples I could find online. It looks like this: require 'test_helper' require 'minitest/mock' require 'rake' class TestScrapeWelcome < ActiveSupport::TestCase def setup …
Camden Narzt
  • 2,271
  • 1
  • 23
  • 42
7
votes
1 answer

How to build task 'elasticsearch:import:model'

Well, I have elasticsearch-rails gem installed (version 0.1.5) and I can clearly see the task inside the gem files. But when I run bundle exec rake environment elasticsearch:import:model CLASS='Comment' I get this error. Running rake environment…
renatojf
  • 734
  • 2
  • 11
  • 29
7
votes
2 answers

Rake dependency not executing but invoke works

I've been trying to run rake db:test:clone_structure, but it keeps failing to rebuild the database. I finally looked at the task itself: task :clone_structure => [ "db:structure:dump", "db:test:load_structure" ] When I run the trace, I've noticed…
abeger
  • 6,766
  • 7
  • 41
  • 58
7
votes
2 answers

Use environment variables in Rake task

task :some_task, :environment do |t, args| puts Rails.env #=> development, production, etc puts ENV #=> {} end I set some environment variables (either via a local .env, or via Heroku Config via Herokusan), such as which AWS bucket to use, and…
Narfanator
  • 5,595
  • 3
  • 39
  • 71
7
votes
2 answers

Multithreaded rake task

I'm writing a rake task that would be called every minute (possibly every 30 seconds in the future) by Whenever, and it contacts a polling API endpoint (per user in our database). Obviously, this is not efficient run as a single thread, but is it…
sleepy_keita
  • 1,488
  • 4
  • 17
  • 26
6
votes
1 answer

using rake to dump and load database

How can I specify a directory for dumping/loading my db to yaml? rake db:data:dump_dir created db/2011-08-31_14:10:57_+0100/ and rake db:data:load_dir No such file or directory - /db/base My question is whether you can specify a…
Viktor Trón
  • 8,774
  • 4
  • 45
  • 48
1 2
3
45 46