Skip to content

Commit

Permalink
Merge pull request #411 from isucon/feature/inject-urls-for-livestream
Browse files Browse the repository at this point in the history
Feature/inject urls for livestream
  • Loading branch information
kazeburo authored Nov 25, 2023
2 parents 4b03bda + aeedc63 commit 2b8e5b0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bench/internal/bencherror/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var ErrTimeout = errors.New("タイムアウトによりリクエスト失敗")
// ベンチマーカー本体由来のエラー

func NewInternalError(err error) error {
err = fmt.Errorf("[ベンチ本体のエラー] スタッフにのみ表示されます: %w", err)
err = fmt.Errorf("[致命的なエラー]: %w", err)
return WrapInternalError(SystemError, err)
}

Expand Down
25 changes: 23 additions & 2 deletions bench/internal/scheduler/reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scheduler

import (
"log"
"math/rand"
"time"

"github.com/biogo/store/interval"
Expand All @@ -26,6 +27,23 @@ func ConvertFromIntInterface(i []interval.IntInterface) ([]*Reservation, error)
return reservations, nil
}

type ReservationUrls struct {
ThumbnailUrl string
PlaylistUrl string
}

var urls = []*ReservationUrls{
&ReservationUrls{ThumbnailUrl: "https://media.xiii.isucon.dev/BBB.webp", PlaylistUrl: "https://media.xiii.isucon.dev/bbb.m3u8"},
&ReservationUrls{ThumbnailUrl: "https://media.xiii.isucon.dev/timewarp.webp", PlaylistUrl: "https://media.xiii.isucon.dev/timewarp.m3u8"},
&ReservationUrls{ThumbnailUrl: "https://media.xiii.isucon.dev/yoru.webp", PlaylistUrl: "https://media.xiii.isucon.dev/yoru.m3u8"},
&ReservationUrls{ThumbnailUrl: "https://media.xiii.isucon.dev/isucon11_final.webp", PlaylistUrl: "https://media.xiii.isucon.dev/isucon11_final.m3u8"},
&ReservationUrls{ThumbnailUrl: "https://media.xiii.isucon.dev/isucon12_final_live.webp", PlaylistUrl: "https://media.xiii.isucon.dev/isucon12_final_live.m3u8"},
&ReservationUrls{ThumbnailUrl: "https://media.xiii.isucon.dev/isucon13.webp", PlaylistUrl: "https://media.xiii.isucon.dev/isucon13.m3u8"},
&ReservationUrls{ThumbnailUrl: "https://media.xiii.isucon.dev/isucon9.webp", PlaylistUrl: "https://media.xiii.isucon.dev/isucon9.m3u8"},
&ReservationUrls{ThumbnailUrl: "https://media.xiii.isucon.dev/hkd.webp", PlaylistUrl: "https://media.xiii.isucon.dev/hkd.m3u8"},
&ReservationUrls{ThumbnailUrl: "https://media.xiii.isucon.dev/ube.webp", PlaylistUrl: "https://media.xiii.isucon.dev/ube.m3u8"},
}

type Reservation struct {
// NOTE: id は、webappで割り振られるIDではなく、ReservationSchedulerが管理する上で利用するもの
id int
Expand All @@ -48,14 +66,17 @@ func mustNewReservation(id int, title string, description string, startAtStr str
log.Fatalln(err)
}

urlIdx := rand.Intn(len(urls))
url := urls[urlIdx]

reservation := &Reservation{
id: id,
Title: title,
Description: description,
StartAt: startAt.Unix(),
EndAt: endAt.Unix(),
PlaylistUrl: playlistUrl,
ThumbnailUrl: thumbnailUrl,
PlaylistUrl: url.PlaylistUrl,
ThumbnailUrl: url.ThumbnailUrl,
}

return reservation
Expand Down
18 changes: 9 additions & 9 deletions bench/internal/scheduler/reservation_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func mustNewReservationScheduler(baseAt int64, numSlots int64, hours int) *Reser

intervalTempertures, err := newIntervalTemperture(baseAt, numSlots, hours)
if err != nil {
lgr.Fatalf("failed to initiate interval temperture: %s\n", err.Error())
lgr.Warnf("failed to initiate interval temperture: %s\n", err.Error())
}
return &ReservationScheduler{
reservationPool: []*Reservation{},
Expand Down Expand Up @@ -126,7 +126,7 @@ func (r *ReservationScheduler) GetHotShortReservation() (*Reservation, error) {

reservations, err := ConvertFromIntInterface(founds)
if err != nil {
lgr.Fatalf("GetHotShortReservation: failed to convert reservation: %s\n", err.Error())
lgr.Warnf("GetHotShortReservation: failed to convert reservation: %s\n", err.Error())
return nil, err
}

Expand All @@ -142,7 +142,7 @@ func (r *ReservationScheduler) GetHotShortReservation() (*Reservation, error) {
}
}

lgr.Fatal("GetHotShortReservation: failed to get reservation (not found)")
lgr.Warn("GetHotShortReservation: failed to get reservation (not found)")
return nil, ErrNoReservation
}

Expand Down Expand Up @@ -171,7 +171,7 @@ func (r *ReservationScheduler) GetHotLongReservation() (*Reservation, error) {

reservations, err := ConvertFromIntInterface(founds)
if err != nil {
lgr.Fatalf("GetHotLongReservation: failed to convert reservation: %s\n", err.Error())
lgr.Warnf("GetHotLongReservation: failed to convert reservation: %s\n", err.Error())
return nil, err
}

Expand All @@ -187,7 +187,7 @@ func (r *ReservationScheduler) GetHotLongReservation() (*Reservation, error) {
}
}

lgr.Fatal("GetHotLongReservation: failed to get reservation (not found)")
lgr.Warn("GetHotLongReservation: failed to get reservation (not found)")
return nil, ErrNoReservation
}

Expand Down Expand Up @@ -216,7 +216,7 @@ func (r *ReservationScheduler) GetColdShortReservation() (*Reservation, error) {

reservations, err := ConvertFromIntInterface(founds)
if err != nil {
lgr.Fatalf("GetColdShortReservation: failed to convert reservation: %s\n", err.Error())
lgr.Warnf("GetColdShortReservation: failed to convert reservation: %s\n", err.Error())
return nil, err
}

Expand All @@ -233,7 +233,7 @@ func (r *ReservationScheduler) GetColdShortReservation() (*Reservation, error) {
}
}

lgr.Fatal("GetColdShortReservation: failed to get reservation (not found)")
lgr.Warn("GetColdShortReservation: failed to get reservation (not found)")
return nil, ErrNoReservation
}

Expand Down Expand Up @@ -262,7 +262,7 @@ func (r *ReservationScheduler) GetColdLongReservation() (*Reservation, error) {

reservations, err := ConvertFromIntInterface(founds)
if err != nil {
lgr.Fatalf("GetColdLongReservation: failed to convert reservation: %s\n", err.Error())
lgr.Warnf("GetColdLongReservation: failed to convert reservation: %s\n", err.Error())
return nil, err
}

Expand All @@ -279,7 +279,7 @@ func (r *ReservationScheduler) GetColdLongReservation() (*Reservation, error) {
}
}

lgr.Fatal("GetColdLongReservation: failed to get reservation (not found)")
lgr.Warn("GetColdLongReservation: failed to get reservation (not found)")
return nil, ErrNoReservation
}

Expand Down
4 changes: 0 additions & 4 deletions bench/isupipe/client_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,5 @@ func (c *Client) GetPaymentResult(ctx context.Context) (*PaymentResult, error) {
return nil, err
}

if err := ValidateResponse(req, paymentResp); err != nil {
return nil, err
}

return paymentResp, nil
}

0 comments on commit 2b8e5b0

Please sign in to comment.