[#4604] Force clearing any lockfiles when submitted from the web
This commit is contained in:
@@ -23,10 +23,10 @@ class RateCachesController < ApplicationController
|
|||||||
def update
|
def update
|
||||||
if params[:cache].present?
|
if params[:cache].present?
|
||||||
if params[:cache].match(/missing/)
|
if params[:cache].match(/missing/)
|
||||||
Rate.update_all_time_entries_with_missing_cost
|
Rate.update_all_time_entries_with_missing_cost(:force => true)
|
||||||
flash[:notice] = l(:text_caches_loaded_successfully)
|
flash[:notice] = l(:text_caches_loaded_successfully)
|
||||||
elsif params[:cache].match(/reload/)
|
elsif params[:cache].match(/reload/)
|
||||||
Rate.update_all_time_entries_to_refresh_cache
|
Rate.update_all_time_entries_to_refresh_cache(:force => true)
|
||||||
flash[:notice] = l(:text_caches_loaded_successfully)
|
flash[:notice] = l(:text_caches_loaded_successfully)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ require 'lockfile'
|
|||||||
class Rate < ActiveRecord::Base
|
class Rate < ActiveRecord::Base
|
||||||
unloadable
|
unloadable
|
||||||
class InvalidParameterException < Exception; end
|
class InvalidParameterException < Exception; end
|
||||||
|
CACHING_LOCK_FILE_NAME = 'rate_cache'
|
||||||
|
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
@@ -70,8 +71,8 @@ class Rate < ActiveRecord::Base
|
|||||||
return rate.amount
|
return rate.amount
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update_all_time_entries_with_missing_cost
|
def self.update_all_time_entries_with_missing_cost(options={})
|
||||||
Lockfile('update_cost_cache', :retries => 0) do
|
with_common_lockfile(options[:force]) do
|
||||||
TimeEntry.all(:conditions => {:cost => nil}).each do |time_entry|
|
TimeEntry.all(:conditions => {:cost => nil}).each do |time_entry|
|
||||||
begin
|
begin
|
||||||
time_entry.save_cached_cost
|
time_entry.save_cached_cost
|
||||||
@@ -83,8 +84,8 @@ class Rate < ActiveRecord::Base
|
|||||||
store_cache_timestamp('last_caching_run', Time.now.to_s)
|
store_cache_timestamp('last_caching_run', Time.now.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update_all_time_entries_to_refresh_cache
|
def self.update_all_time_entries_to_refresh_cache(options={})
|
||||||
Lockfile('refresh_cache', :retries => 0) do
|
with_common_lockfile(options[:force]) do
|
||||||
TimeEntry.find_each do |time_entry| # batch find
|
TimeEntry.find_each do |time_entry| # batch find
|
||||||
begin
|
begin
|
||||||
time_entry.save_cached_cost
|
time_entry.save_cached_cost
|
||||||
@@ -139,6 +140,16 @@ class Rate < ActiveRecord::Base
|
|||||||
Setting.plugin_redmine_rate = Setting.plugin_redmine_rate.merge({cache_name => timestamp})
|
Setting.plugin_redmine_rate = Setting.plugin_redmine_rate.merge({cache_name => timestamp})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.with_common_lockfile(force = false, &block)
|
||||||
|
# Wait 1 second after stealing a forced lock
|
||||||
|
options = {:retries => 0, :suspend => 1}
|
||||||
|
options[:max_age] = 1 if force
|
||||||
|
|
||||||
|
Lockfile(CACHING_LOCK_FILE_NAME, options) do
|
||||||
|
block.call
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if Rails.env.test?
|
if Rails.env.test?
|
||||||
public
|
public
|
||||||
generator_for :date_in_effect => Date.today
|
generator_for :date_in_effect => Date.today
|
||||||
|
|||||||
Reference in New Issue
Block a user