From 486fafedddb2149164b7468329030d5633446ae1 Mon Sep 17 00:00:00 2001 From: Max Fliri Date: Tue, 19 Feb 2013 11:16:46 +0000 Subject: [PATCH] Rake tasks to collect last week data only @maxfliri --- lib/tasks/collect.rake | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/tasks/collect.rake b/lib/tasks/collect.rake index 18b296e..ec57db1 100644 --- a/lib/tasks/collect.rake +++ b/lib/tasks/collect.rake @@ -18,14 +18,36 @@ collector_spec = [ ] namespace :collect do - desc "Initially collect Google Analytics data" initialisation_tasks = Hash[collector_spec.map { |spec| [("init_" + underscore(spec[:config])).to_sym, spec] }] + + desc "Initially collect Google Analytics data and send to queue" task :init => initialisation_tasks.keys + initialisation_tasks.each do |key, params| - task key do + task key, :days_ago, :command do |t, args| + args.with_defaults(:days_ago => params[:days_ago], :command => "broadcast") rack_env = ENV.fetch('RACK_ENV', 'development') root_path = File.expand_path(File.dirname(__FILE__) + "/../../") - sh %{cd #{root_path} && RACK_ENV=#{rack_env} bundle exec collector --config=#{params[:config]} --days_ago=#{params[:days_ago]} broadcast} + sh %{cd #{root_path} && RACK_ENV=#{rack_env} bundle exec collector --config=#{params[:config]} --days_ago=#{args[:days_ago]} #{args[:command]}} + end + end + + task :last_week, :command do |t, args| + args.with_defaults(:command => "broadcast") + initialisation_tasks.each do |task, _| + Rake::Task["collect:#{task}"].invoke(7, args[:command]) + end + end + + namespace :last_week do + desc "collect data for last week and print" + task :print do + Rake::Task["last_week"].invoke("print") + end + + desc "collect data for last week and send to queue" + task :broadcast do + Rake::Task["last_week"].invoke("broadcast") end end end \ No newline at end of file