diff --git a/app/services/tournament_sync_enqueue.rb b/app/services/tournament_sync_enqueue.rb index f4bd3a8..056ab18 100644 --- a/app/services/tournament_sync_enqueue.rb +++ b/app/services/tournament_sync_enqueue.rb @@ -12,7 +12,7 @@ class TournamentSyncEnqueue def call return false unless tournament.sync_push_enabled? - payload = TournamentSnapshotBuilder.build(tournament) + payload = TournamentSnapshotBuilder.build(fresh_tournament) entry = TournamentSyncQueueEntry.find_or_initialize_by(tournament: tournament) entry.snapshot_json = JSON.dump(payload) entry.status = 'pending' @@ -28,4 +28,8 @@ class TournamentSyncEnqueue private attr_reader :tournament + + def fresh_tournament + Tournament.find(tournament.id) + end end diff --git a/tasks.py b/tasks.py index 40f3cc9..a6dfb9e 100644 --- a/tasks.py +++ b/tasks.py @@ -1330,6 +1330,74 @@ Tournament.order(:id).pluck(:id, :name, :read_only_mode, :sync_target_url, :sync print(output.rstrip()) +@task(name="docker-blackbox-follow-debug-compare") +def docker_blackbox_follow_debug_compare( + c, + source_host_port=BLACKBOX_SOURCE_HOST_PORT, + follower_host_port=BLACKBOX_FOLLOWER_HOST_PORT, + app_image=PRODUCTION_TAG, + runner_image=TEST_TAG, + postgres_image=BLACKBOX_POSTGRES_IMAGE, +): + """Compare latest leader tournament and follower read-only tournament via HTTP API.""" + env = _follow_compose_env( + source_host_port=source_host_port, + follower_host_port=follower_host_port, + app_image=app_image, + runner_image=runner_image, + postgres_image=postgres_image, + ) + + script = """ +def signature(tournament) + { + id: tournament.id, + name: tournament.name, + public: tournament.public, + playoff_teams_amount: tournament.playoff_teams_amount, + instant_finalists_amount: tournament.instant_finalists_amount, + intermediate_round_participants_amount: tournament.intermediate_round_participants_amount, + sync_source_tournament_id: tournament.respond_to?(:sync_source_tournament_id) ? tournament.sync_source_tournament_id : nil, + team_names: tournament.teams.order(:id).pluck(:name), + stage_levels: tournament.stages.order(:level).map { |stage| [stage.level, stage.state, stage.groups.count, stage.matches.count] }, + total_matches: tournament.matches.count, + decider_matches: tournament.matches.count(&:decider?) + } +end + +tournament = if ENV['FOLLOW_COMPARE_MODE'] == 'leader' + Tournament.where.not(sync_target_url: nil).order(:id).last + else + Tournament.where(read_only_mode: true).order(:id).last + end + +puts signature(tournament).inspect +""" + + for mode, db_host, db_name in (("leader", "source-postgres", BLACKBOX_SOURCE_DB_NAME), ("follower", "follower-postgres", BLACKBOX_FOLLOWER_DB_NAME)): + _print_header(f"Compare {mode} tournament") + service_env = _production_env_for(db_host, db_name) + runner = _compose_run( + ["run", "--rm", "-e", f"POSTGRES_URL={service_env['POSTGRES_URL']}", "-e", f"POSTGRES_USERNAME={service_env['POSTGRES_USERNAME']}", "-e", f"POSTGRES_PASSWORD={service_env['POSTGRES_PASSWORD']}", "-e", f"SECRET_KEY_BASE={service_env['SECRET_KEY_BASE']}", "-e", f"MAILGUN_API_KEY={service_env['MAILGUN_API_KEY']}", "-e", f"MAILGUN_DOMAIN={service_env['MAILGUN_DOMAIN']}", "-e", f"RAILS_LOG_TO_STDOUT={service_env['RAILS_LOG_TO_STDOUT']}", "-e", f"RAILS_SERVE_STATIC_FILES={service_env['RAILS_SERVE_STATIC_FILES']}", "-e", "RAILS_ENV=production", "-e", f"FOLLOW_COMPARE_MODE={mode}", "e2e", "bundle", "exec", "rails", "runner", script], + env=env, + capture_output=True, + check=False, + project_name=BLACKBOX_FOLLOW_PROJECT, + compose_file=BLACKBOX_FOLLOW_COMPOSE_FILE, + ) + if runner.stdout: + print(runner.stdout.rstrip()) + if runner.stderr: + print(runner.stderr.rstrip()) + if runner.returncode != 0: + raise subprocess.CalledProcessError( + runner.returncode, + runner.args, + output=runner.stdout, + stderr=runner.stderr, + ) + + @task(name="docker-blackbox-follow-run") def docker_blackbox_follow_run( c,