Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run one rake task after another completes

I'm trying to split down a rake task that i have,

What im wanting to do is after the rake task completes, It fires off another rake task.

Is this possible and if so how?

like image 335
sam roberts Avatar asked Mar 08 '16 18:03

sam roberts


2 Answers

You can use enhance to extend one task with other:

task :extra_behavior do
  # extra
end

Rake::Task["first:task"].enhance do
  Rake::Task[:extra_behavior].invoke
end
  • Reference
  • Reference
like image 149
Philidor Avatar answered Nov 14 '22 19:11

Philidor


Passing a task as an argument to enhance causes it to run BEFORE the task you are "enhancing".

Rake::Task["task_A"].enhance(["task_B"])
# Runs task_B
# Runs task_A

Passing a task to enhance in a block causes it to run AFTER the task you are "enhancing".

Rake::Task["task_A"].enhance do
  Rake::Task["task_B"].execute
end
# Runs task_A
# Runs task_B

Reference: Rake Task enhance Method Explained

like image 1
Ivo Dimitrov Avatar answered Nov 14 '22 19:11

Ivo Dimitrov