[#4604] Move method to model
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
require 'lockfile'
|
||||||
|
|
||||||
class Rate < ActiveRecord::Base
|
class Rate < ActiveRecord::Base
|
||||||
unloadable
|
unloadable
|
||||||
class InvalidParameterException < Exception; end
|
class InvalidParameterException < Exception; end
|
||||||
@@ -67,6 +69,18 @@ class Rate < ActiveRecord::Base
|
|||||||
return nil if rate.nil?
|
return nil if rate.nil?
|
||||||
return rate.amount
|
return rate.amount
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.update_all_time_entires_with_missing_cost
|
||||||
|
Lockfile('update_cost_cache', :retries => 0) do
|
||||||
|
TimeEntry.all(:conditions => {:cost => nil}).each do |time_entry|
|
||||||
|
begin
|
||||||
|
time_entry.save_cached_cost
|
||||||
|
rescue Rate::InvalidParameterException => ex
|
||||||
|
puts "Error saving #{time_entry.id}: #{ex.message}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def self.for_user_project_and_date(user, project, date)
|
def self.for_user_project_and_date(user, project, date)
|
||||||
|
|||||||
@@ -1,20 +1,8 @@
|
|||||||
require 'lockfile'
|
|
||||||
|
|
||||||
namespace :rate_plugin do
|
namespace :rate_plugin do
|
||||||
namespace :cache do
|
namespace :cache do
|
||||||
desc "Update Time Entry cost caches"
|
desc "Update Time Entry cost caches"
|
||||||
task :update_cost_cache => :environment do
|
task :update_cost_cache => :environment do
|
||||||
Lockfile('update_cost_cache', :retries => 0) do
|
Rate.update_all_time_entires_with_missing_cost
|
||||||
TimeEntry.all(:conditions => {:cost => nil}).each do |time_entry|
|
|
||||||
begin
|
|
||||||
time_entry.save_cached_cost
|
|
||||||
rescue Rate::InvalidParameterException => ex
|
|
||||||
puts "Error saving #{time_entry.id}: #{ex.message}"
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user