Skip to content

Commit

Permalink
Merge pull request #402 from internetee/fix-contact-request
Browse files Browse the repository at this point in the history
Added syncing loop with delay for contact requests
  • Loading branch information
vohmar authored Mar 21, 2024
2 parents a039b44 + 9773725 commit c4d45aa
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
24 changes: 10 additions & 14 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-18.04]
ruby: [2.6, 2.7]
os: [ubuntu-22.04]
ruby: ['2.7', '3.0.3']
runs-on: ${{ matrix.os }}
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand Down Expand Up @@ -55,9 +55,6 @@ jobs:
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
- name: setup-chromedriver
uses: nanasess/[email protected]

- name: Run Tests
env:
PG_DATABASE: postgres
Expand All @@ -75,13 +72,17 @@ jobs:
- name: Save coverage
run: ./cc-test-reporter format-coverage --output coverage/codeclimate.${{ matrix.ruby }}.json

- uses: actions/[email protected].2
- uses: actions/[email protected].3
with:
name: coverage-${{ matrix.ruby }}
path: coverage/codeclimate.${{ matrix.ruby }}.json

upload_coverage:
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
ruby: [ '2.7', '3.0.3' ]
runs-on: ubuntu-22.04

env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
Expand All @@ -98,12 +99,7 @@ jobs:

- uses: actions/[email protected]
with:
name: coverage-2.6
path: coverage

- uses: actions/[email protected]
with:
name: coverage-2.7
name: coverage-${{ matrix.ruby }}
path: coverage

- name: Aggregate & upload results to Code Climate
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.3
3.0.3
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM internetee/ruby:2.7
MAINTAINER [email protected]
FROM internetee/ruby:3.0-buster

RUN mkdir -p /opt/webapps/app/tmp/pids
WORKDIR /opt/webapps/app
Expand Down
39 changes: 30 additions & 9 deletions app/controllers/contact_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class ContactRequestsController < ApplicationController
before_action :set_contact_request, only: %i[edit update show]
before_action :check_for_replay, only: %i[edit update show]

MAX_SYNC_WAIT_TIME = 5 # seconds

rescue_from ActionController::UnknownFormat do
logger.warn("The unlucky customer was using format of: #{request.format}")
raise
Expand All @@ -17,20 +19,15 @@ def new
def create
@contact_request = ContactRequest.new(contact_request_params)
result = @contact_request.save_to_registry
@contact_request = result ? ContactRequest.find_by(id: result['id']) : nil
fetch_contact_request(result)

if @contact_request
update_request_secret
@contact_request.send_confirmation_email
@contact_request.reload
logger.warn("Confirmation request email registered to #{@contact_request.email}" \
" (IP: #{request.ip})")
render :confirmation_completed
process_contact_request
else
redirect_to(:root, alert: t('contact_requests.registry_link_error'))
end
rescue Net::SMTPServerBusy => e
logger.warn("Failed confirmation request email to #{@contact_request.email}. #{e.message}")
redirect_to(:root, alert: t('contact_requests.smtp_error'))
handle_smtp_error(e)
end

def redirect_to_main
Expand Down Expand Up @@ -87,4 +84,28 @@ def check_for_replay
def contact_request_params
params.require(:contact_request).permit(:email, :whois_record_id, :name)
end

def fetch_contact_request(result)
start_time = Time.now
while Time.now - start_time < MAX_SYNC_WAIT_TIME
@contact_request = result ? ContactRequest.find_by(id: result['id']) : nil
break if @contact_request

sleep(0.5) # Sleep for 0.5 seconds before retrying
end
end

def process_contact_request
update_request_secret
@contact_request.send_confirmation_email
@contact_request.reload
logger.warn("Confirmation request email registered to #{@contact_request.email}" \
" (IP: #{request.ip})")
render :confirmation_completed
end

def handle_smtp_error(exception)
logger.warn("Failed confirmation request email to #{@contact_request.email}. #{exception.message}")
redirect_to(:root, alert: t('contact_requests.smtp_error'))
end
end
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@

# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end

0 comments on commit c4d45aa

Please sign in to comment.