Skip to content

Commit

Permalink
Write filenames to shutdown prep bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
glacials committed Feb 8, 2025
1 parent 5539303 commit 9fc970c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/controllers/api/v3/runs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def create
key: "splits/#{filename}",
body: params.require(:file)
)
$s3_shutdown_prep_bucket.put_object(
key: @run.id,
body: filename,
)
$s3_shutdown_prep_bucket.put_object(
key: "extensions/#{@run.id}",
body: @run.program.file_extension,
)

render status: :created, location: api_v3_run_url(@run), json: {
status: 201,
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/api/v4/converts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def create
key: "splits/#{filename}",
body: params.require(:file)
)
$s3_shutdown_prep_bucket.put_object(
key: @run.id,
body: filename,
)


@run.parse_into_db
if @run.program.nil?
Expand All @@ -25,6 +30,10 @@ def create
}
return
end
$s3_shutdown_prep_bucket.put_object(
key: "extensions/#{@run.id}",
body: @run.program.file_extension,
)

# Use a new find by to eager load the segment histories to prevent n+1 queries
@run = Run.includes(segments: [:histories]).find(@run.id)
Expand Down
8 changes: 8 additions & 0 deletions app/models/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ def split(more: false, realtime_end_ms: nil, gametime_end_ms: nil) # rubocop:tod
locals: {:@run => self},
),
)
$s3_shutdown_prep_bucket.put_object(
key: id,
body: s3_filename,
)
$s3_shutdown_prep_bucket.put_object(
key: "extensions/#{@run.id}",
body: @run.program.file_extension,
)

save
end
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@

$s3_bucket_internal = Aws::S3::Bucket.new(ENV['S3_BUCKET'], client: $s3_client_internal)
$s3_bucket_external = Aws::S3::Bucket.new(ENV['S3_BUCKET'], client: $s3_client_external)

$s3_shutdown_prep_bucket = Aws::S3::Bucket.new("splits.io-runid-to-s3filename", client: $s3_client_internal)

0 comments on commit 9fc970c

Please sign in to comment.