Search code examples
ruby-on-railsrakerake-task

Ruby On Rails - Is it possible to store the result of a Rake Task?


In my api, I'd like to run a rake task every 10 minutes(for instance at 8:00, 8:10..). This task can take up to 10 minutes to execute(Thus, the next task can start its execution before the first one ends). Since this task executes a lot of time-consuming queries at the beginning, I thought about splitting my rake task to two:

  1. The first will execute these time-consuming queries. I'll fire this task every 10 minutes(at 8:05, 8:15...).
  2. I'd like to use the result of the queries executed at the first rake task in the second one(which will be fired at 8:10, 8:20).

I was wondering if there is way a to store the result of the first rake task and use it in the second one? Or, is there another way to do what I am planing to build?

FYI, I don't want to use database storage since writing/reading takes a lot of time.


Solution

  • This makes no sense on the face of it. If your second task is dependent on your first, and your first only prepares data for the second, you either need to store the data in the database, or (more sensibly) just make it one task. Whatever other non-database storage solutions you come up with aren't going to be any better than a database.

    If you need it to be two tasks, then modularlize things. Use three tasks; the first two can be run independently, and the third will invoke the first and pass the result to the second.