diff --git a/.github/workflows/pr-auto-create.yml b/.github/workflows/pr-auto-create.yml deleted file mode 100644 index 3f7385cc..00000000 --- a/.github/workflows/pr-auto-create.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Auto Create Release PR - -on: - # trigger on push to dev branch - push: - branches: - - dev - # trigger on manual workflow_dispatch - workflow_dispatch: - -concurrency: - group: pr-creator-${{ github.ref }} - cancel-in-progress: true - -jobs: - pr-creator: - name: Create PR - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - ref: "dev" - - # create a PR from dev to main, with title in form: Release - # where, is the next version number to be released, based on the last release in git tag - - name: Create PR - uses: actions/github-script@v6 - # ignore errors if PR already exists - continue-on-error: true - with: - github-token: ${{ secrets.PAT_FOR_RELEASE_TAGGER }} - script: | - const { data: { tag_name: lastRelease } } = await github.rest.repos.getLatestRelease({ - owner: context.repo.owner, - repo: context.repo.repo - }) - const nextRelease = lastRelease.replace(/(\d+)$/, (match, p1) => Number(p1) + 1) - const prTitle = `Release ${nextRelease}` - const pr = await github.rest.pulls.create({ - owner: context.repo.owner, - repo: context.repo.repo, - title: prTitle, - body: `> *This PR is automatically created by actions defined in this repository. To see the run log of this action, please click [here](/${{ github.repository }}/actions/runs/${{ github.run_id }})*`, - head: context.ref, - base: 'main', - draft: true - }) diff --git a/.github/workflows/pr-auto-upsert.yml b/.github/workflows/pr-auto-upsert.yml new file mode 100644 index 00000000..ad7290b9 --- /dev/null +++ b/.github/workflows/pr-auto-upsert.yml @@ -0,0 +1,119 @@ +name: Auto Upsert Release PR + +on: + # trigger on push to dev branch + push: + branches: + - dev + # trigger on manual workflow_dispatch + workflow_dispatch: + +concurrency: + group: pr-upsert-${{ github.ref }} + cancel-in-progress: true + +jobs: + pr-upsert: + name: Upsert PR + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + ref: "dev" + # fetch all history so that git log can get all commit messages + fetch-depth: 0 + + - id: get_summary + name: Get summary from GPT + continue-on-error: true + run: | + # get all commit messages from last release tag to HEAD + git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:%s > /tmp/commit_messages.txt + + # replace newlines with \n + sed -i ':a;N;$!ba;s/\n/\\n/g' /tmp/commit_messages.txt + + echo "commit messages: $(cat /tmp/commit_messages.txt)" + + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" \ + -d '{ + "model": "gpt-3.5-turbo", + "messages": [ + { + "role": "system", + "content": "You are now a git commit message summarizer. By analyzing commit messages, you should provide a concise summary, highlighting key changes and updates made in each commit. This can save time and improve clarity for developers working in collaborative projects.\n\nCommits are typically constructed using the Conventional Commit standard.\n\nYour summarized message should consist of 1-3 sentences that are compacted into sentences for each of the categories (e.g. Added, Fixed, Removed). You should NOT use bullet points." + }, + { + "role": "user", + "content": "feat: remove deleted required flag\nbuild: add workflow_dispatch\nfeat: add rowsAffected & fix json struct tag\nchore: add logs" + }, + { + "role": "assistant", + "content": "Added: `workflow_dispatch`, `rowsAffected`, logs.\nFixed: JSON struct tag.\nRemoved: required flag of `deleted`." + }, + { + "role": "user", + "content": "$(cat /tmp/commit_messages.txt)" + } + ], + "temperature": 1, + "max_tokens": 256, + "top_p": 1, + "frequency_penalty": 0.1, + "presence_penalty": 0.2 + }' | jq -r '.choices[0].message.content' > /tmp/summary.txt + + # replace newlines with spaces + sed -i ':a;N;$!ba;s/\n/ /g' /tmp/summary.txt + + # replace " with \" + sed -i 's/"/\\"/g' /tmp/summary.txt + + echo "summary: $(cat /tmp/summary.txt)" + + echo "summary=$(cat /tmp/summary.txt)" >> $GITHUB_OUTPUT + + # create a PR from dev to main, with title in form: Release + # where, is the next version number to be released, based on the last release in git tag + - name: Create PR + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.PAT_FOR_RELEASE_TAGGER }} + script: | + const { data: { tag_name: lastRelease } } = await github.rest.repos.getLatestRelease({ + owner: context.repo.owner, + repo: context.repo.repo + }) + const nextRelease = lastRelease.replace(/(\d+)$/, (match, p1) => Number(p1) + 1) + const prTitle = `Release ${nextRelease}` + let body = `> *This PR is automatically created by actions defined in this repository. To see the run log of this action, please click [here](/${{ github.repository }}/actions/runs/${{ github.run_id }})*\n\n---\n\n## Summary\n\n` + body += "${{ steps.get_summary.outputs.summary || '(no summary)' }}" + const existedPR = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + head: `${context.repo.owner}:dev`, + base: 'main' + }) + if (existedPR.data.length > 0) { + core.info(`PR already exists: ${existedPR.data[0].html_url}. Updating body...`) + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: existedPR.data[0].number, + body: body + }) + core.info(`PR updated: ${existedPR.data[0].html_url}`) + return + } + const pr = await github.rest.pulls.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: prTitle, + body: body, + head: context.ref, + base: 'main', + draft: true + }) diff --git a/go.mod b/go.mod index d6235da6..f281a1e4 100644 --- a/go.mod +++ b/go.mod @@ -62,8 +62,7 @@ require ( golang.org/x/exp v0.0.0-20220823124025-807a23277127 golang.org/x/mod v0.9.0 golang.org/x/sync v0.5.0 - golang.org/x/text v0.13.0 - google.golang.org/grpc v1.55.0 + golang.org/x/text v0.14.0 google.golang.org/protobuf v1.30.0 gopkg.in/DataDog/dd-trace-go.v1 v1.48.0 gopkg.in/guregu/null.v3 v3.5.0 @@ -116,6 +115,7 @@ require ( go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect go.opentelemetry.io/proto/otlp v0.19.0 // indirect google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect + google.golang.org/grpc v1.55.0 // indirect ) require ( diff --git a/go.sum b/go.sum index 4fceefde..e87a1eda 100644 --- a/go.sum +++ b/go.sum @@ -69,8 +69,6 @@ github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.1 h1:ZY3108YtBNq96jNZ github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.1/go.mod h1:t8PYl/6LzdAqsU4/9tz28V/kU+asFePvpOMkdul0gEQ= github.com/aws/aws-sdk-go-v2/config v1.25.4 h1:r+X1x8QI6FEPdJDWCNBDZHyAcyFwSjHN8q8uuus+Axs= github.com/aws/aws-sdk-go-v2/config v1.25.4/go.mod h1:8GTjImECskr7D88P/Nn9uM4M4rLY9i77hLJZgkZEWV8= -github.com/aws/aws-sdk-go-v2/credentials v1.16.3 h1:8PeI2krzzjDJ5etmgaMiD1JswsrLrWvKKu/uBUtNy1g= -github.com/aws/aws-sdk-go-v2/credentials v1.16.3/go.mod h1:Kdh/okh+//vQ/AjEt81CjvkTo64+/zIE4OewP7RpfXk= github.com/aws/aws-sdk-go-v2/credentials v1.16.4 h1:i7UQYYDSJrtc30RSwJwfBKwLFNnBTiICqAJ0pPdum8E= github.com/aws/aws-sdk-go-v2/credentials v1.16.4/go.mod h1:Kdh/okh+//vQ/AjEt81CjvkTo64+/zIE4OewP7RpfXk= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.5 h1:KehRNiVzIfAcj6gw98zotVbb/K67taJE0fkfgM6vzqU= @@ -761,6 +759,8 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/internal/app/appconfig/spec.go b/internal/app/appconfig/spec.go index f920a5de..7dc57e32 100644 --- a/internal/app/appconfig/spec.go +++ b/internal/app/appconfig/spec.go @@ -62,12 +62,6 @@ type ConfigSpec struct { // SentryDSN is the DSN of the Sentry server. See https://pkg.go.dev/github.com/getsentry/sentry-go#ClientOptions SentryDSN string `split_words:"true"` - // LiveHouseEnabled to indicate whether to enable LiveHouse reporting. - LiveHouseEnabled bool `split_words:"true" default:"false"` - - // LiveHouseGRPCAddress is the address of the LiveHouse gRPC server. - LiveHouseGRPCAddress string `split_words:"true" default:"localhost:9015"` - // DatadogProfilerEnabled to indicate whether to enable Datadog profiler. DatadogProfilerEnabled bool `split_words:"true" default:"false"` diff --git a/internal/infra/0module.go b/internal/infra/0module.go index ee7c2cca..f597bb08 100644 --- a/internal/infra/0module.go +++ b/internal/infra/0module.go @@ -8,7 +8,6 @@ func Module() fx.Option { Redis, RedSync, Postgres, - LiveHouse, GeoIPDatabase, ), fx.Invoke(Datadog)) } diff --git a/internal/infra/livehouse.go b/internal/infra/livehouse.go deleted file mode 100644 index f51c0e3e..00000000 --- a/internal/infra/livehouse.go +++ /dev/null @@ -1,26 +0,0 @@ -package infra - -import ( - "github.com/rs/zerolog/log" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" - - "exusiai.dev/backend-next/internal/app/appconfig" - "exusiai.dev/backend-next/internal/model/pb" -) - -func LiveHouse(conf *appconfig.Config) (pb.ConnectedLiveServiceClient, error) { - if conf.LiveHouseEnabled { - conn, err := grpc.Dial(conf.LiveHouseGRPCAddress, grpc.WithTransportCredentials(insecure.NewCredentials())) - if err != nil { - log.Error().Err(err).Msg("infra: failed to connect to livehouse") - return nil, err - } - - return pb.NewConnectedLiveServiceClient(conn), nil - } else { - log.Info().Msg("infra: livehouse is disabled") - } - - return nil, nil -} diff --git a/internal/model/pb/liveconn.pb.go b/internal/model/pb/liveconn.pb.go deleted file mode 100644 index 8be263cd..00000000 --- a/internal/model/pb/liveconn.pb.go +++ /dev/null @@ -1,620 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.0 -// protoc v3.21.7 -// source: liveconn.proto - -package pb - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type ReportBatchRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Reports []*Report `protobuf:"bytes,1,rep,name=reports,proto3" json:"reports,omitempty"` -} - -func (x *ReportBatchRequest) Reset() { - *x = ReportBatchRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_liveconn_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ReportBatchRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ReportBatchRequest) ProtoMessage() {} - -func (x *ReportBatchRequest) ProtoReflect() protoreflect.Message { - mi := &file_liveconn_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ReportBatchRequest.ProtoReflect.Descriptor instead. -func (*ReportBatchRequest) Descriptor() ([]byte, []int) { - return file_liveconn_proto_rawDescGZIP(), []int{0} -} - -func (x *ReportBatchRequest) GetReports() []*Report { - if x != nil { - return x.Reports - } - return nil -} - -type ReportBatchACK struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *ReportBatchACK) Reset() { - *x = ReportBatchACK{} - if protoimpl.UnsafeEnabled { - mi := &file_liveconn_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ReportBatchACK) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ReportBatchACK) ProtoMessage() {} - -func (x *ReportBatchACK) ProtoReflect() protoreflect.Message { - mi := &file_liveconn_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ReportBatchACK.ProtoReflect.Descriptor instead. -func (*ReportBatchACK) Descriptor() ([]byte, []int) { - return file_liveconn_proto_rawDescGZIP(), []int{1} -} - -type Report struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Server Server `protobuf:"varint,1,opt,name=server,proto3,enum=Server" json:"server,omitempty"` - Generation uint64 `protobuf:"varint,2,opt,name=generation,proto3" json:"generation,omitempty"` - StageId uint32 `protobuf:"varint,3,opt,name=stage_id,json=stageId,proto3" json:"stage_id,omitempty"` - Drops []*Drop `protobuf:"bytes,4,rep,name=drops,proto3" json:"drops,omitempty"` -} - -func (x *Report) Reset() { - *x = Report{} - if protoimpl.UnsafeEnabled { - mi := &file_liveconn_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Report) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Report) ProtoMessage() {} - -func (x *Report) ProtoReflect() protoreflect.Message { - mi := &file_liveconn_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Report.ProtoReflect.Descriptor instead. -func (*Report) Descriptor() ([]byte, []int) { - return file_liveconn_proto_rawDescGZIP(), []int{2} -} - -func (x *Report) GetServer() Server { - if x != nil { - return x.Server - } - return Server_CN -} - -func (x *Report) GetGeneration() uint64 { - if x != nil { - return x.Generation - } - return 0 -} - -func (x *Report) GetStageId() uint32 { - if x != nil { - return x.StageId - } - return 0 -} - -func (x *Report) GetDrops() []*Drop { - if x != nil { - return x.Drops - } - return nil -} - -type Drop struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - ItemId uint32 `protobuf:"varint,1,opt,name=item_id,json=itemId,proto3" json:"item_id,omitempty"` - Quantity uint64 `protobuf:"varint,2,opt,name=quantity,proto3" json:"quantity,omitempty"` -} - -func (x *Drop) Reset() { - *x = Drop{} - if protoimpl.UnsafeEnabled { - mi := &file_liveconn_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Drop) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Drop) ProtoMessage() {} - -func (x *Drop) ProtoReflect() protoreflect.Message { - mi := &file_liveconn_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Drop.ProtoReflect.Descriptor instead. -func (*Drop) Descriptor() ([]byte, []int) { - return file_liveconn_proto_rawDescGZIP(), []int{3} -} - -func (x *Drop) GetItemId() uint32 { - if x != nil { - return x.ItemId - } - return 0 -} - -func (x *Drop) GetQuantity() uint64 { - if x != nil { - return x.Quantity - } - return 0 -} - -type MatrixBatchRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Server Server `protobuf:"varint,1,opt,name=server,proto3,enum=Server" json:"server,omitempty"` - Generation uint64 `protobuf:"varint,2,opt,name=generation,proto3" json:"generation,omitempty"` - Matrix []*Matrix `protobuf:"bytes,3,rep,name=matrix,proto3" json:"matrix,omitempty"` -} - -func (x *MatrixBatchRequest) Reset() { - *x = MatrixBatchRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_liveconn_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *MatrixBatchRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MatrixBatchRequest) ProtoMessage() {} - -func (x *MatrixBatchRequest) ProtoReflect() protoreflect.Message { - mi := &file_liveconn_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use MatrixBatchRequest.ProtoReflect.Descriptor instead. -func (*MatrixBatchRequest) Descriptor() ([]byte, []int) { - return file_liveconn_proto_rawDescGZIP(), []int{4} -} - -func (x *MatrixBatchRequest) GetServer() Server { - if x != nil { - return x.Server - } - return Server_CN -} - -func (x *MatrixBatchRequest) GetGeneration() uint64 { - if x != nil { - return x.Generation - } - return 0 -} - -func (x *MatrixBatchRequest) GetMatrix() []*Matrix { - if x != nil { - return x.Matrix - } - return nil -} - -type MatrixBatchACK struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Generation uint64 `protobuf:"varint,1,opt,name=generation,proto3" json:"generation,omitempty"` -} - -func (x *MatrixBatchACK) Reset() { - *x = MatrixBatchACK{} - if protoimpl.UnsafeEnabled { - mi := &file_liveconn_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *MatrixBatchACK) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MatrixBatchACK) ProtoMessage() {} - -func (x *MatrixBatchACK) ProtoReflect() protoreflect.Message { - mi := &file_liveconn_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use MatrixBatchACK.ProtoReflect.Descriptor instead. -func (*MatrixBatchACK) Descriptor() ([]byte, []int) { - return file_liveconn_proto_rawDescGZIP(), []int{5} -} - -func (x *MatrixBatchACK) GetGeneration() uint64 { - if x != nil { - return x.Generation - } - return 0 -} - -type Matrix struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - StageId uint32 `protobuf:"varint,1,opt,name=stage_id,json=stageId,proto3" json:"stage_id,omitempty"` - ItemId uint32 `protobuf:"varint,2,opt,name=item_id,json=itemId,proto3" json:"item_id,omitempty"` - Quantity uint64 `protobuf:"varint,3,opt,name=quantity,proto3" json:"quantity,omitempty"` - Times uint64 `protobuf:"varint,4,opt,name=times,proto3" json:"times,omitempty"` -} - -func (x *Matrix) Reset() { - *x = Matrix{} - if protoimpl.UnsafeEnabled { - mi := &file_liveconn_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Matrix) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Matrix) ProtoMessage() {} - -func (x *Matrix) ProtoReflect() protoreflect.Message { - mi := &file_liveconn_proto_msgTypes[6] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Matrix.ProtoReflect.Descriptor instead. -func (*Matrix) Descriptor() ([]byte, []int) { - return file_liveconn_proto_rawDescGZIP(), []int{6} -} - -func (x *Matrix) GetStageId() uint32 { - if x != nil { - return x.StageId - } - return 0 -} - -func (x *Matrix) GetItemId() uint32 { - if x != nil { - return x.ItemId - } - return 0 -} - -func (x *Matrix) GetQuantity() uint64 { - if x != nil { - return x.Quantity - } - return 0 -} - -func (x *Matrix) GetTimes() uint64 { - if x != nil { - return x.Times - } - return 0 -} - -var File_liveconn_proto protoreflect.FileDescriptor - -var file_liveconn_proto_rawDesc = []byte{ - 0x0a, 0x0e, 0x6c, 0x69, 0x76, 0x65, 0x63, 0x6f, 0x6e, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x1a, 0x0c, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x37, - 0x0a, 0x12, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x07, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x18, - 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x07, - 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x22, 0x10, 0x0a, 0x0e, 0x52, 0x65, 0x70, 0x6f, 0x72, - 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x41, 0x43, 0x4b, 0x22, 0x81, 0x01, 0x0a, 0x06, 0x52, 0x65, - 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1f, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0e, 0x32, 0x07, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x06, 0x73, - 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1e, 0x0a, 0x0a, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a, 0x67, 0x65, 0x6e, 0x65, 0x72, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, - 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x73, 0x74, 0x61, 0x67, 0x65, 0x49, 0x64, - 0x12, 0x1b, 0x0a, 0x05, 0x64, 0x72, 0x6f, 0x70, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x05, 0x2e, 0x44, 0x72, 0x6f, 0x70, 0x52, 0x05, 0x64, 0x72, 0x6f, 0x70, 0x73, 0x22, 0x3b, 0x0a, - 0x04, 0x44, 0x72, 0x6f, 0x70, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x74, 0x65, 0x6d, 0x5f, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x69, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x1a, - 0x0a, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, - 0x52, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x22, 0x76, 0x0a, 0x12, 0x4d, 0x61, - 0x74, 0x72, 0x69, 0x78, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x1f, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, - 0x32, 0x07, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, - 0x72, 0x12, 0x1e, 0x0a, 0x0a, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x12, 0x1f, 0x0a, 0x06, 0x6d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x18, 0x03, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x07, 0x2e, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x52, 0x06, 0x6d, 0x61, 0x74, 0x72, - 0x69, 0x78, 0x22, 0x30, 0x0a, 0x0e, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x42, 0x61, 0x74, 0x63, - 0x68, 0x41, 0x43, 0x4b, 0x12, 0x1e, 0x0a, 0x0a, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x6e, 0x0a, 0x06, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x12, 0x19, - 0x0a, 0x08, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, - 0x52, 0x07, 0x73, 0x74, 0x61, 0x67, 0x65, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x74, 0x65, - 0x6d, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x69, 0x74, 0x65, 0x6d, - 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x14, - 0x0a, 0x05, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x74, - 0x69, 0x6d, 0x65, 0x73, 0x32, 0x8c, 0x01, 0x0a, 0x14, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, - 0x65, 0x64, 0x4c, 0x69, 0x76, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x39, 0x0a, - 0x0f, 0x50, 0x75, 0x73, 0x68, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, - 0x12, 0x13, 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0f, 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x42, 0x61, - 0x74, 0x63, 0x68, 0x41, 0x43, 0x4b, 0x22, 0x00, 0x12, 0x39, 0x0a, 0x0f, 0x50, 0x75, 0x73, 0x68, - 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x42, 0x61, 0x74, 0x63, 0x68, 0x12, 0x13, 0x2e, 0x4d, 0x61, - 0x74, 0x72, 0x69, 0x78, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x0f, 0x2e, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x42, 0x61, 0x74, 0x63, 0x68, 0x41, 0x43, - 0x4b, 0x22, 0x00, 0x42, 0x3e, 0x5a, 0x3c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x70, 0x65, 0x6e, 0x67, 0x75, 0x69, 0x6e, 0x2d, 0x73, 0x74, 0x61, 0x74, 0x69, 0x73, - 0x74, 0x69, 0x63, 0x73, 0x2f, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x2d, 0x6e, 0x65, 0x78, - 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, - 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_liveconn_proto_rawDescOnce sync.Once - file_liveconn_proto_rawDescData = file_liveconn_proto_rawDesc -) - -func file_liveconn_proto_rawDescGZIP() []byte { - file_liveconn_proto_rawDescOnce.Do(func() { - file_liveconn_proto_rawDescData = protoimpl.X.CompressGZIP(file_liveconn_proto_rawDescData) - }) - return file_liveconn_proto_rawDescData -} - -var file_liveconn_proto_msgTypes = make([]protoimpl.MessageInfo, 7) -var file_liveconn_proto_goTypes = []interface{}{ - (*ReportBatchRequest)(nil), // 0: ReportBatchRequest - (*ReportBatchACK)(nil), // 1: ReportBatchACK - (*Report)(nil), // 2: Report - (*Drop)(nil), // 3: Drop - (*MatrixBatchRequest)(nil), // 4: MatrixBatchRequest - (*MatrixBatchACK)(nil), // 5: MatrixBatchACK - (*Matrix)(nil), // 6: Matrix - (Server)(0), // 7: Server -} -var file_liveconn_proto_depIdxs = []int32{ - 2, // 0: ReportBatchRequest.reports:type_name -> Report - 7, // 1: Report.server:type_name -> Server - 3, // 2: Report.drops:type_name -> Drop - 7, // 3: MatrixBatchRequest.server:type_name -> Server - 6, // 4: MatrixBatchRequest.matrix:type_name -> Matrix - 0, // 5: ConnectedLiveService.PushReportBatch:input_type -> ReportBatchRequest - 4, // 6: ConnectedLiveService.PushMatrixBatch:input_type -> MatrixBatchRequest - 1, // 7: ConnectedLiveService.PushReportBatch:output_type -> ReportBatchACK - 5, // 8: ConnectedLiveService.PushMatrixBatch:output_type -> MatrixBatchACK - 7, // [7:9] is the sub-list for method output_type - 5, // [5:7] is the sub-list for method input_type - 5, // [5:5] is the sub-list for extension type_name - 5, // [5:5] is the sub-list for extension extendee - 0, // [0:5] is the sub-list for field type_name -} - -func init() { file_liveconn_proto_init() } -func file_liveconn_proto_init() { - if File_liveconn_proto != nil { - return - } - file_shared_proto_init() - if !protoimpl.UnsafeEnabled { - file_liveconn_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ReportBatchRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_liveconn_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ReportBatchACK); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_liveconn_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Report); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_liveconn_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Drop); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_liveconn_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*MatrixBatchRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_liveconn_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*MatrixBatchACK); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_liveconn_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Matrix); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_liveconn_proto_rawDesc, - NumEnums: 0, - NumMessages: 7, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_liveconn_proto_goTypes, - DependencyIndexes: file_liveconn_proto_depIdxs, - MessageInfos: file_liveconn_proto_msgTypes, - }.Build() - File_liveconn_proto = out.File - file_liveconn_proto_rawDesc = nil - file_liveconn_proto_goTypes = nil - file_liveconn_proto_depIdxs = nil -} diff --git a/internal/model/pb/liveconn.proto b/internal/model/pb/liveconn.proto deleted file mode 100644 index c232f5a4..00000000 --- a/internal/model/pb/liveconn.proto +++ /dev/null @@ -1,45 +0,0 @@ -syntax = "proto3"; - -import "shared.proto"; - -option go_package = "exusiai.dev/backend-next/internal/model/pb"; - -service ConnectedLiveService { - rpc PushReportBatch(ReportBatchRequest) returns (ReportBatchACK) {} - rpc PushMatrixBatch(MatrixBatchRequest) returns (MatrixBatchACK) {} -} - -message ReportBatchRequest { - repeated Report reports = 1; -} - -message ReportBatchACK {} - -message Report { - Server server = 1; - uint64 generation = 2; - uint32 stage_id = 3; - repeated Drop drops = 4; -} - -message Drop { - uint32 item_id = 1; - uint64 quantity = 2; -} - -message MatrixBatchRequest { - Server server = 1; - uint64 generation = 2; - repeated Matrix matrix = 3; -} - -message MatrixBatchACK { - uint64 generation = 1; -} - -message Matrix { - uint32 stage_id = 1; - uint32 item_id = 2; - uint64 quantity = 3; - uint64 times = 4; -} diff --git a/internal/model/pb/liveconn_grpc.pb.go b/internal/model/pb/liveconn_grpc.pb.go deleted file mode 100644 index 1141f170..00000000 --- a/internal/model/pb/liveconn_grpc.pb.go +++ /dev/null @@ -1,141 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.2.0 -// - protoc v3.21.7 -// source: liveconn.proto - -package pb - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -// ConnectedLiveServiceClient is the client API for ConnectedLiveService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type ConnectedLiveServiceClient interface { - PushReportBatch(ctx context.Context, in *ReportBatchRequest, opts ...grpc.CallOption) (*ReportBatchACK, error) - PushMatrixBatch(ctx context.Context, in *MatrixBatchRequest, opts ...grpc.CallOption) (*MatrixBatchACK, error) -} - -type connectedLiveServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewConnectedLiveServiceClient(cc grpc.ClientConnInterface) ConnectedLiveServiceClient { - return &connectedLiveServiceClient{cc} -} - -func (c *connectedLiveServiceClient) PushReportBatch(ctx context.Context, in *ReportBatchRequest, opts ...grpc.CallOption) (*ReportBatchACK, error) { - out := new(ReportBatchACK) - err := c.cc.Invoke(ctx, "/ConnectedLiveService/PushReportBatch", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *connectedLiveServiceClient) PushMatrixBatch(ctx context.Context, in *MatrixBatchRequest, opts ...grpc.CallOption) (*MatrixBatchACK, error) { - out := new(MatrixBatchACK) - err := c.cc.Invoke(ctx, "/ConnectedLiveService/PushMatrixBatch", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// ConnectedLiveServiceServer is the server API for ConnectedLiveService service. -// All implementations must embed UnimplementedConnectedLiveServiceServer -// for forward compatibility -type ConnectedLiveServiceServer interface { - PushReportBatch(context.Context, *ReportBatchRequest) (*ReportBatchACK, error) - PushMatrixBatch(context.Context, *MatrixBatchRequest) (*MatrixBatchACK, error) - mustEmbedUnimplementedConnectedLiveServiceServer() -} - -// UnimplementedConnectedLiveServiceServer must be embedded to have forward compatible implementations. -type UnimplementedConnectedLiveServiceServer struct { -} - -func (UnimplementedConnectedLiveServiceServer) PushReportBatch(context.Context, *ReportBatchRequest) (*ReportBatchACK, error) { - return nil, status.Errorf(codes.Unimplemented, "method PushReportBatch not implemented") -} -func (UnimplementedConnectedLiveServiceServer) PushMatrixBatch(context.Context, *MatrixBatchRequest) (*MatrixBatchACK, error) { - return nil, status.Errorf(codes.Unimplemented, "method PushMatrixBatch not implemented") -} -func (UnimplementedConnectedLiveServiceServer) mustEmbedUnimplementedConnectedLiveServiceServer() {} - -// UnsafeConnectedLiveServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to ConnectedLiveServiceServer will -// result in compilation errors. -type UnsafeConnectedLiveServiceServer interface { - mustEmbedUnimplementedConnectedLiveServiceServer() -} - -func RegisterConnectedLiveServiceServer(s grpc.ServiceRegistrar, srv ConnectedLiveServiceServer) { - s.RegisterService(&ConnectedLiveService_ServiceDesc, srv) -} - -func _ConnectedLiveService_PushReportBatch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ReportBatchRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ConnectedLiveServiceServer).PushReportBatch(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/ConnectedLiveService/PushReportBatch", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ConnectedLiveServiceServer).PushReportBatch(ctx, req.(*ReportBatchRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _ConnectedLiveService_PushMatrixBatch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MatrixBatchRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ConnectedLiveServiceServer).PushMatrixBatch(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/ConnectedLiveService/PushMatrixBatch", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ConnectedLiveServiceServer).PushMatrixBatch(ctx, req.(*MatrixBatchRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// ConnectedLiveService_ServiceDesc is the grpc.ServiceDesc for ConnectedLiveService service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var ConnectedLiveService_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "ConnectedLiveService", - HandlerType: (*ConnectedLiveServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "PushReportBatch", - Handler: _ConnectedLiveService_PushReportBatch_Handler, - }, - { - MethodName: "PushMatrixBatch", - Handler: _ConnectedLiveService_PushMatrixBatch_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "liveconn.proto", -} diff --git a/internal/service/0module.go b/internal/service/0module.go index f5c7a2db..02db5592 100644 --- a/internal/service/0module.go +++ b/internal/service/0module.go @@ -24,7 +24,6 @@ func Module() fx.Option { NewShortURL, NewSnapshot, NewAnalytics, - NewLiveHouse, NewSiteStats, NewTimeRange, NewDropMatrix, diff --git a/internal/service/livehouse.go b/internal/service/livehouse.go deleted file mode 100644 index 12360af9..00000000 --- a/internal/service/livehouse.go +++ /dev/null @@ -1,122 +0,0 @@ -package service - -import ( - "context" - "sync/atomic" - "time" - - "github.com/pkg/errors" - "github.com/rs/zerolog/log" - - "exusiai.dev/backend-next/internal/app/appconfig" - "exusiai.dev/backend-next/internal/model/pb" - "exusiai.dev/backend-next/internal/model/types" - "exusiai.dev/backend-next/internal/pkg/dstructs" - "exusiai.dev/backend-next/internal/repo" - "exusiai.dev/gommon/constant" -) - -type LiveHouse struct { - Enabled bool - Client pb.ConnectedLiveServiceClient - StageRepo *repo.Stage - - q *dstructs.FlQueue[*pb.Report] - t *time.Ticker - gen uint64 -} - -func NewLiveHouse(client pb.ConnectedLiveServiceClient, stageRepo *repo.Stage, conf *appconfig.Config) (*LiveHouse, error) { - l := &LiveHouse{ - Enabled: conf.LiveHouseEnabled, - Client: client, - StageRepo: stageRepo, - q: dstructs.NewFlQueue[*pb.Report](), - t: time.NewTicker(time.Second * 5), - } - - if l.Enabled { - if err := l.checkConfig(); err != nil { - return nil, err - } - - go l.worker() - } else { - log.Info(). - Str("evt.name", "livehouse.disabled"). - Msg("service: livehouse: disabled") - } - - return l, nil -} - -func (l *LiveHouse) checkConfig() error { - if l.Client == nil { - return errors.New("service: livehouse: client is nil. is livehouse enabled?") - } - if l.StageRepo == nil { - return errors.New("service: livehouse: stage repo is nil") - } - - return nil -} - -func (l *LiveHouse) worker() { - for range l.t.C { - reports := l.q.Flush() - if len(reports) == 0 { - continue - } - - _, err := l.Client.PushReportBatch(context.Background(), &pb.ReportBatchRequest{ - Reports: reports, - }) - if err != nil { - log.Error(). - Str("evt.name", "livehouse.report.failed"). - Err(err). - Msg("failed to push report batch") - } else { - log.Info(). - Str("evt.name", "livehouse.report.success"). - Int("count", len(reports)). - Msg("successfully reported reports to livehouse") - } - } -} - -func (l *LiveHouse) PushReport(r *types.ReportTaskSingleReport, stageId uint32, server string) error { - if !l.Enabled { - return nil - } - - var pbserv pb.Server - if m, ok := constant.ServerIDMapping[server]; ok { - pbserv = pb.Server(m) - } else { - return errors.New("service: livehouse: unknown server") - } - - pr := &pb.Report{ - Server: pbserv, - Generation: atomic.LoadUint64(&l.gen), - StageId: stageId, - Drops: make([]*pb.Drop, 0, len(r.Drops)), - } - for _, d := range r.Drops { - pr.Drops = append(pr.Drops, &pb.Drop{ - ItemId: uint32(d.ItemID), - Quantity: uint64(d.Quantity), - }) - } - l.q.Push(pr) - - return nil -} - -func (l *LiveHouse) PushMatrix() { - if !l.Enabled { - return - } - atomic.AddUint64(&l.gen, 1) -} diff --git a/internal/workers/reportwkr/reportwkr.go b/internal/workers/reportwkr/reportwkr.go index 54d814db..5e516dc3 100644 --- a/internal/workers/reportwkr/reportwkr.go +++ b/internal/workers/reportwkr/reportwkr.go @@ -44,7 +44,6 @@ type WorkerDeps struct { DropReportExtraRepo *repo.DropReportExtra DropPatternElementRepo *repo.DropPatternElement ReportVerifier *reportverifs.ReportVerifiers - LiveHouseService *service.LiveHouse } type Worker struct { @@ -271,6 +270,12 @@ func (w *Worker) process(ctx context.Context, reportTask *types.ReportTask) erro } if reportTask.IP == "" { // FIXME: temporary hack; find why ip is empty + log.Warn(). + Str("evt.name", "reportwkr.ip.empty"). + Str("taskId", reportTask.TaskID). + Interface("reportTask", reportTask). + Msg("ip is empty; using 127.0.0.1 as a fallback") + reportTask.IP = "127.0.0.1" } if err = w.DropReportExtraRepo.CreateDropReportExtra(pstCtx, tx, &model.DropReportExtra{ @@ -285,12 +290,6 @@ func (w *Worker) process(ctx context.Context, reportTask *types.ReportTask) erro if err := w.Redis.Set(pstCtx, constant.ReportRedisPrefix+reportTask.TaskID, dropReport.ReportID, time.Hour*24).Err(); err != nil { return errors.Wrap(err, "failed to set report id in redis") } - - if reliability == 0 { - if err := w.LiveHouseService.PushReport(report, uint32(stage.StageID), reportTask.Server); err != nil { - L.Warn().Err(err).Msg("failed to push report to LiveHouse") - } - } } intendedCommit = true