Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple_captcha_data: ignore all error during data flushing #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/simple_captcha/simple_captcha_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ def get_data(key)
end

def remove_data(key)
where(["#{connection.quote_column_name(:key)} = ?", key]).delete_all
clear_old_data(1.hour.ago)
begin
where(["#{connection.quote_column_name(:key)} = ?", key]).delete_all
clear_old_data(1.hour.ago)
rescue StandardError => err
Rails.logger.error "#{err.class} #{err.message}"
end
end

def clear_old_data(time = 1.hour.ago)
return unless Time === time
where(["#{connection.quote_column_name(:updated_at)} < ?", time]).delete_all
rescue ActiveRecord::Deadlocked => err
rescue StandardError => err
Rails.logger.error "#{err.class} #{err.message}"
end
end
Expand Down