Skip to content
This repository has been archived by the owner on Apr 4, 2018. It is now read-only.

Commit

Permalink
Rake tasks to collect last week data only
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Fliri committed Feb 19, 2013
1 parent 2bbc8b9 commit 486fafe
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions lib/tasks/collect.rake
Expand Up @@ -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

0 comments on commit 486fafe

Please sign in to comment.