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
4
votes
3 answers

What is the best practice to use asserts in Ruby, but not as part of unit tests?

I want to use an assert to raise an error within a rake task. the_index = items.index(some_item) assert_not_nil the_index, "Lookup failed for the following item: " + some_item I get undefined method assert_not_nil. Can I include the assertions file…
B Seven
  • 44,484
  • 66
  • 240
  • 385
4
votes
1 answer

Rake task - with additional class

I have my own classes, which I want to use in my rake task. Where to put files with this classes?
Kir
  • 7,981
  • 12
  • 52
  • 69
4
votes
1 answer

accessing rails models from rake task

How can I access model objects from rails rake task? If I initialize my rufus scheduler $scheduler = Rufus::Scheduler.start_new in my rake would that scheduler stay alive since it's from a rake task?
ed1t
  • 8,719
  • 17
  • 67
  • 110
4
votes
1 answer

Heroku Scheduler task not running as expected

I'm using Heroku's Scheduler add-on to run jobs in my app at scheduled time intervals, much like cron in a traditional server environment. The tasks are rather trivial, in it that they simply enqueue a sidekiq worker. However, as you can see in the…
VegaStudios
  • 378
  • 1
  • 4
  • 22
4
votes
1 answer

How to clear memory for a long running rake task to prevent exceeding Heroku's memory quota?

I have a rake task that I need to run on Heroku in the background as a one off task. However the tasks is pretty large and I run into a 'Error R14 (Memory Quota Exceeded)` and was hoping I could get some tips on how I can avoid this. Essentially the…
8bithero
  • 1,474
  • 1
  • 18
  • 23
4
votes
2 answers

How to set up a Rake task for seeding

(This is really a newbie question about Rake & Rails & dependencies in general. Trying to wrap my head around how all this fits together) Basically, I want a Rake task that acts like seed.rb but is called separately. It adds test data for the…
Mike Blyth
  • 4,158
  • 4
  • 30
  • 41
4
votes
1 answer

Overriding rake tasks and rake task dependencies?

I'm using a build system which defines a number of rake targets, including this one: task :test => [:all] This seems incorrect to me, and so I defined my own rake tasks like so: task :test => [:spec] task :all => [:test, :build] task :release =>…
Dasmowenator
  • 5,505
  • 5
  • 36
  • 50
4
votes
3 answers

NameError: uninitialized constant Rails::TestTask

I put this code inside my Rakefile in order to be able to run tests from an additional folder "test/classes" (not just from test/models, test/controllers etc): # Adding test/classes directory to rake test. namespace :test do # line 9 desc "Test…
Sergey
  • 47,222
  • 25
  • 87
  • 129
4
votes
2 answers

Cannot load namespaced model when invoking rake task

I got a rake task which invokes other rake tasks, so my development data can be easily reset. the first rake task (lib/tasks/populate.rake) # Rake task to populate development database with test data # Run it with "rake db:populate" namespace :db…
Flo
  • 540
  • 6
  • 20
4
votes
2 answers

Rake aborted! Don't know how to build task

I have a rake task in semester.rake file. It looks like this namespace :db do desc "generate semester data" task semester: :environment do semester = Semester.create!(name: "SummerSemseter") semester = Semester.create!(name:…
user1670773
4
votes
1 answer

Can I include helper methods in rake tasks

I have methods that execute Nokogiri. i.e. Download pages, extract content, copy to another tables... etc. This methods are inside helper that I need to run periodically by rake task. Whats the proper way to call the methods in a task DRY. Move code…
4
votes
3 answers

Is it possible to include a module in rake tasks without polluting the global scope?

I wonder — is it possible to create private helpers for rake tasks, no matter how I try to do it they end up being available in the in the global scope and also are available as methods of any object. For example: ## this is what I need module…
Dmitry Sokurenko
  • 6,042
  • 4
  • 32
  • 53
4
votes
1 answer

Don't know how to build task 'rake tmp:clear'

I'm used to enhance rake tasks, but today rake do not want to collaborate... In particular I want to enhance rake tmp:clear. And as usual I tried this way: Rake::Task["tmp:clear"].enhance do puts "enhanced" end I always get a Don't know how to…
Flavien
  • 95
  • 9
4
votes
2 answers

What is the best way to schedule `whenever` task in rails in midnight usa?

We have a Rails 4 application . What is the best way to schedule whenever task in rails in midnight usa with daylight saving ? We need to send email at 11.58pm in night of a day's report . We are using tzinfo…
Debadatt
  • 5,935
  • 4
  • 27
  • 40
4
votes
3 answers

rake namespace vs. ruby module

How can I have helper functions with the same name in different rake tasks? The following code does not work: # bar.rake namespace :bar do desc 'bar' task :bar => :environment do bar end def bar puts "bar bar" end end #…
thorstenhirsch
  • 199
  • 3
  • 14