Enqueue sync after transaction commit
This commit is contained in:
parent
9cfd0c9444
commit
8bdd7fd1be
|
|
@ -66,6 +66,7 @@ class MatchesController < ApplicationController
|
||||||
# PATCH/PUT /matches/1
|
# PATCH/PUT /matches/1
|
||||||
def update
|
def update
|
||||||
new_state = match_params['state']
|
new_state = match_params['state']
|
||||||
|
synced_tournament = nil
|
||||||
|
|
||||||
Match.transaction do
|
Match.transaction do
|
||||||
if @match.update(match_params)
|
if @match.update(match_params)
|
||||||
|
|
@ -78,12 +79,13 @@ class MatchesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: @match
|
render json: @match
|
||||||
push_sync_if_needed!(@match.tournament)
|
synced_tournament = @match.tournament
|
||||||
else
|
else
|
||||||
render json: @match.errors, status: :unprocessable_entity
|
render json: @match.errors, status: :unprocessable_entity
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
push_sync_if_needed!(synced_tournament) unless synced_tournament.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
|
|
@ -19,17 +19,19 @@ class StagesController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
synced_tournament = nil
|
||||||
Stage.transaction do
|
Stage.transaction do
|
||||||
if @stage.update(stage_params)
|
if @stage.update(stage_params)
|
||||||
handle_group_stage_end
|
handle_group_stage_end
|
||||||
|
|
||||||
render json: @stage
|
render json: @stage
|
||||||
push_sync_if_needed!(@stage.tournament)
|
synced_tournament = @stage.tournament
|
||||||
else
|
else
|
||||||
render json: @stage.errors, status: :unprocessable_entity
|
render json: @stage.errors, status: :unprocessable_entity
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
push_sync_if_needed!(synced_tournament) unless synced_tournament.nil?
|
||||||
else
|
else
|
||||||
render json: {
|
render json: {
|
||||||
error: 'The state attribute may only be changed to finished'
|
error: 'The state attribute may only be changed to finished'
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ class TournamentsController < ApplicationController
|
||||||
|
|
||||||
# PATCH/PUT /tournaments/1
|
# PATCH/PUT /tournaments/1
|
||||||
def update
|
def update
|
||||||
|
synced_tournament = nil
|
||||||
Tournament.transaction do
|
Tournament.transaction do
|
||||||
if only_playoff_teams_amount_changed
|
if only_playoff_teams_amount_changed
|
||||||
@tournament.instant_finalists_amount, @tournament.intermediate_round_participants_amount =
|
@tournament.instant_finalists_amount, @tournament.intermediate_round_participants_amount =
|
||||||
|
|
@ -94,13 +95,14 @@ class TournamentsController < ApplicationController
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
if @tournament.update(tournament_params)
|
if @tournament.update(tournament_params)
|
||||||
push_sync_if_needed!(@tournament)
|
synced_tournament = @tournament
|
||||||
render json: @tournament
|
render json: @tournament
|
||||||
else
|
else
|
||||||
render json: @tournament.errors, status: :unprocessable_entity
|
render json: @tournament.errors, status: :unprocessable_entity
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
push_sync_if_needed!(synced_tournament) unless synced_tournament.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /tournaments/1
|
# DELETE /tournaments/1
|
||||||
|
|
|
||||||
|
|
@ -55,11 +55,11 @@ RSpec.describe StagesController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'adds new stages to the tournament' do
|
it 'adds new stages to the tournament' do
|
||||||
expect(running_group_stage.tournament.stages.size).to be > 1
|
expect(running_group_stage.tournament.reload.stages.size).to be > 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'adds the right teams' do
|
it 'adds the right teams' do
|
||||||
expect(running_group_stage.tournament.stages.max_by(&:level).teams)
|
expect(running_group_stage.tournament.reload.stages.max_by(&:level).teams)
|
||||||
.to match_array(GroupStageService.get_advancing_teams(running_group_stage))
|
.to match_array(GroupStageService.get_advancing_teams(running_group_stage))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue