2013-09-02 14:19:44 +02:00
|
|
|
# This namespace is used for a collection of tasks to maintain a hosting environment with multiple foodcoops
|
|
|
|
# This tasks are a kind of wrapper for other tasks. The wrapper makes sure, that the appropriate database and config
|
|
|
|
# for each foodcoop is used.
|
|
|
|
|
2012-08-27 08:24:25 +02:00
|
|
|
namespace :multicoops do
|
2013-09-02 14:19:44 +02:00
|
|
|
desc 'Runs a specific rake task for each registered foodcoop, use rake multicoops:run TASK=db:migrate'
|
2023-05-12 13:01:12 +02:00
|
|
|
task run: :environment do
|
2022-05-27 21:57:06 +02:00
|
|
|
task_to_run = ENV.fetch('TASK', nil)
|
2019-10-21 22:53:26 +02:00
|
|
|
last_error = nil
|
2012-08-27 08:24:25 +02:00
|
|
|
FoodsoftConfig.each_coop do |coop|
|
2023-05-12 13:01:12 +02:00
|
|
|
rake_say "Run '#{task_to_run}' for #{coop}"
|
|
|
|
Rake::Task[task_to_run].execute
|
|
|
|
rescue StandardError => e
|
|
|
|
last_error = e
|
|
|
|
ExceptionNotifier.notify_exception(e, data: { foodcoop: coop })
|
2012-08-27 08:24:25 +02:00
|
|
|
end
|
2019-10-21 22:53:26 +02:00
|
|
|
raise last_error if last_error
|
2012-08-27 08:24:25 +02:00
|
|
|
end
|
|
|
|
|
2013-09-02 14:19:44 +02:00
|
|
|
desc 'Runs a specific rake task for a single coop, use rake mutlicoops:run_single TASK=db:migrate FOODCOOP=demo'
|
2023-05-12 13:01:12 +02:00
|
|
|
task run_single: :environment do
|
2022-05-27 21:57:06 +02:00
|
|
|
task_to_run = ENV.fetch('TASK', nil)
|
|
|
|
FoodsoftConfig.select_foodcoop ENV.fetch('FOODCOOP', nil)
|
|
|
|
rake_say "Run '#{task_to_run}' for #{ENV.fetch('FOODCOOP', nil)}"
|
2013-01-07 13:44:46 +01:00
|
|
|
Rake::Task[task_to_run].execute
|
2012-12-24 12:50:37 +01:00
|
|
|
end
|
2013-01-07 13:44:46 +01:00
|
|
|
end
|
2013-09-25 11:57:22 +02:00
|
|
|
|
|
|
|
# Helper
|
2013-09-30 10:57:54 +02:00
|
|
|
def rake_say(message)
|
2021-03-01 15:27:26 +01:00
|
|
|
puts message unless Rake.application.options.silent
|
2013-09-25 11:57:22 +02:00
|
|
|
end
|