diff --git a/config/schedule.rb b/config/schedule.rb index 0578799b..f22c1348 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -7,6 +7,11 @@ every :day, :at => '7:20 am' do rake "multicoops:run TASK=foodsoft:notify_users_of_weekly_task" end +# Import and assign bank transactions +every :weekday, :at => %w(5:56am 6:04pm) do + rake "multicoops:run TASK=foodsoft:import_and_assign_bank_transactions" +end + # Weekly taks every :sunday, :at => '7:14 am' do rake "multicoops:run TASK=foodsoft:create_upcoming_periodic_tasks" diff --git a/lib/tasks/foodsoft.rake b/lib/tasks/foodsoft.rake index 8dbb5f3b..eb7d5852 100644 --- a/lib/tasks/foodsoft.rake +++ b/lib/tasks/foodsoft.rake @@ -63,6 +63,17 @@ namespace :foodsoft do server.start server.join end + + desc "Import and assign bank transactions" + task :import_and_assign_bank_transactions => :environment do + BankAccount.find_each do |ba| + import_method = ba.find_import_method + next unless import_method + import_count = import_method.call(ba) + assign_count = ba.assign_unlinked_transactions + rake_say "#{ba.name}: imported #{import_count}, assigned #{assign_count}" + end + end end # Helper