Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8549813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:48:23+00:00 2026-06-11T13:48:23+00:00

I have a batch of rake tasks that run sequentially: task :batch_tasks => :environment

  • 0

I have a batch of rake tasks that run sequentially:

task :batch_tasks => :environment do
  Rake::Task["db:drop"].execute
  Rake::Task["db:create"].execute
  Rake::Task["db:migrate"].execute
  Rake::Task["db:seed"].execute
  Rake::Task["db:test:prepare"].execute
  Rake::Task["custom_task_1"].execute
end

Here’s what’s in custom_task_1:

task :custom_task_1 => :environment do
  puts "begin custom task"
  orders = Order.all #three records
  orders.each do |order|
    puts "Do something to Order\n"
  end
  puts "end custom task"
end

When I run the above batch process, here’s what happens:

rake batch_tasks
begin custom task
end custom task

But if I run the custom task AFTER the batch process, here’s what happens:

rake custom_task_1
begin custom task
Do something to Order
Do something to Order
Do something to Order
end custom task

One thing to note, when I run debugger on rake batch_tasks with a breakpoint after rake db:seed, a check on eval Order.all returns an empty array []. However, Order.all does have data immediately after all of the rake tasks are finished.

What am I missing about rake db:seed and having access to ActiveRecord data in the next task called?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:48:25+00:00Added an answer on June 11, 2026 at 1:48 pm

    So the quick fix was to move the db:test:prepare line to the end of the batch.

    I believe the problem stemmed from the environment being switched from development to test and then the custom task was running in the last environment, which then had an empty test database.

    The db:seed command probably switches the environment back to dev and the custom task runs against the correct database.

    task :batch_tasks => :environment do
      Rake::Task["db:drop"].execute
      Rake::Task["db:create"].execute
      Rake::Task["db:migrate"].execute
      Rake::Task["db:seed"].execute
      Rake::Task["custom_task_1"].execute
      Rake::Task["db:test:prepare"].execute # <-- Moved after all other tasks
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this batch that needs to run that the user has to execute
I have a rake task that is responsible for doing batch processing on millions
I have a rake task that sends out the next 'x' invitations to join
I have a batch file with some commands that I need to run with
i have a batch(backup.bat)file.in that i have written a command to create a backup
I have a batch file that creates a scheduled task using schtasks like this:
I have a batch script I run before our performance tests that does some
I have batch file that sets up the desktop environment for me when I
I have a batch of reports that are set up to print very nicely
I have a batch script that outputs a file, and I'm trying to ensure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.