Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #308 from JustHumanz/pilot-commands
Browse files Browse the repository at this point in the history
Add pilot commands
  • Loading branch information
JustHumanz authored May 17, 2022
2 parents a86b441 + dc4e736 commit 020bc76
Show file tree
Hide file tree
Showing 18 changed files with 203 additions and 63 deletions.
18 changes: 18 additions & 0 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,3 +745,21 @@ func UnMarshalPayload(Payload []byte) []database.Group {
}
return agency
}

func GetHostname() string {
hostname, err := os.Hostname()
if err != nil {
log.Fatal(err)
}

return hostname
}

func LowerCaseURI(h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
r.URL.Path = strings.ToLower(r.URL.Path)
h.ServeHTTP(w, r)
}

return http.HandlerFunc(fn)
}
2 changes: 2 additions & 0 deletions service/fanart/bilibili/bilibili.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ type checkBlJob struct {

func ReqRunningJob(client pilot.PilotServiceClient) {
Bili := &checkBlJob{}
hostname := engine.GetHostname()

for {
res, err := client.RequestRunJobsOfService(context.Background(), &pilot.ServiceMessage{
Service: ServiceName,
Message: "Request",
ServiceUUID: ServiceUUID,
Hostname: hostname,
})
if err != nil {
log.Error(err)
Expand Down
2 changes: 2 additions & 0 deletions service/fanart/pixiv/pixiv.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,14 @@ type checkPxJob struct {

func ReqRunningJob(client pilot.PilotServiceClient) {
Pix := &checkPxJob{}
hostname := engine.GetHostname()

for {
res, err := client.RequestRunJobsOfService(context.Background(), &pilot.ServiceMessage{
Service: ServiceName,
Message: "Request",
ServiceUUID: ServiceUUID,
Hostname: hostname,
})
if err != nil {
log.Error(err)
Expand Down
2 changes: 2 additions & 0 deletions service/fanart/twitter/twitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ func main() {

func ReqRunningJob(client pilot.PilotServiceClient) {
Twit := &checkTwJob{}
hostname := engine.GetHostname()

for {

res, err := client.RequestRunJobsOfService(context.Background(), &pilot.ServiceMessage{
Service: ServiceName,
Message: "Request",
ServiceUUID: ServiceUUID,
Hostname: hostname,
})
if err != nil {
log.Error(err)
Expand Down
3 changes: 3 additions & 0 deletions service/frontend/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func main() {

configfile.InitConf()

hostname := engine.GetHostname()

go func() {
for {
log.WithFields(log.Fields{
Expand All @@ -83,6 +85,7 @@ func main() {
Service: ServiceName,
Message: "Request",
ServiceUUID: ServiceUUID,
Hostname: hostname,
})
if err != nil {
log.Error(err)
Expand Down
2 changes: 2 additions & 0 deletions service/livestream/bilibili/live/live.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ type checkBlLiveeJob struct {

func ReqRunningJob(client pilot.PilotServiceClient) {
Bili := &checkBlLiveeJob{}
hostname := engine.GetHostname()

for {

res, err := client.RequestRunJobsOfService(context.Background(), &pilot.ServiceMessage{
Service: ServiceName,
Message: "Request",
ServiceUUID: ServiceUUID,
Hostname: hostname,
})
if err != nil {
log.Error(err)
Expand Down
3 changes: 3 additions & 0 deletions service/livestream/bilibili/space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,15 @@ func ReqRunningJob(client pilot.PilotServiceClient) {
VideoIDTMP: make(map[string]string),
}

hostname := engine.GetHostname()

for {

res, err := client.RequestRunJobsOfService(context.Background(), &pilot.ServiceMessage{
Service: ServiceName,
Message: "Request",
ServiceUUID: ServiceUUID,
Hostname: hostname,
})
if err != nil {
log.Error(err)
Expand Down
2 changes: 2 additions & 0 deletions service/livestream/twitch/twitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ type checkTwcJob struct {

func ReqRunningJob(client pilot.PilotServiceClient) {
Twitch := &checkTwcJob{}
hostname := engine.GetHostname()

for {
res, err := client.RequestRunJobsOfService(context.Background(), &pilot.ServiceMessage{
Service: ServiceName,
Message: "Request",
ServiceUUID: ServiceUUID,
Hostname: hostname,
})
if err != nil {
log.Error(err)
Expand Down
5 changes: 5 additions & 0 deletions service/livestream/youtube/checker/youtube.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func ReqRunningJob(client pilot.PilotServiceClient) {
Counter: 1,
Update: true,
}

hostname := engine.GetHostname()

for {

if YoutubeChecker.Counter == 15 {
Expand All @@ -95,6 +98,7 @@ func ReqRunningJob(client pilot.PilotServiceClient) {
Service: ServiceName,
Message: "Update",
ServiceUUID: ServiceUUID,
Hostname: hostname,
})
if err != nil {
log.Error(err)
Expand All @@ -105,6 +109,7 @@ func ReqRunningJob(client pilot.PilotServiceClient) {
Service: ServiceName,
Message: "New",
ServiceUUID: ServiceUUID,
Hostname: hostname,
})
if err != nil {
log.Error(err)
Expand Down
4 changes: 4 additions & 0 deletions service/livestream/youtube/counter/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ func ReqRunningJob(client pilot.PilotServiceClient) {
YoutubeCounter := &checkYtJob{
CekCounter: make(map[string]bool),
}

hostname := engine.GetHostname()

for {

res, err := client.RequestRunJobsOfService(context.Background(), &pilot.ServiceMessage{
Service: ServiceName,
Message: "Request",
ServiceUUID: ServiceUUID,
Hostname: hostname,
})

if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions service/migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ type NewVtuber struct {
}

func RequestPay(Message string) {
hostname := engine.GetHostname()
res, err := gRCPconn.GetBotPayload(context.Background(), &pilot.ServiceMessage{
Message: Message,
Service: "Migrate",
ServiceUUID: ServiceUUID,
Hostname: hostname,
})
if err != nil {
log.Fatalf("Error when request payload: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion service/pilot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ FROM $BASE_IMAGE as base

FROM alpine
COPY --from=base /app/Go-Simp/bin/pilot /pilot
EXPOSE 9000
EXPOSE 9000 8080 8181
CMD ["./pilot"]
25 changes: 20 additions & 5 deletions service/pilot/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,17 @@ type Service struct {
}

type UnitService struct {
UUID string
Counter int
Payload []database.Group
UUID string
Counter int
Payload []database.Group
Metadata UnitMetadata
}

type UnitMetadata struct {
UUID string
Hostname string
Length int
AgencyList []string
}

type Server struct {
Expand Down Expand Up @@ -167,9 +175,11 @@ func (s *Service) RemapPayload() {
AgencyCount := 0
for _, v := range s.Unit {
AgencyCount += len(v.Payload)
v.Metadata.Length = len(v.Payload)
v.Metadata.AgencyList = v.GetAgencyList()
}

if AgencyCount < 29 {
if AgencyCount < 29 && AgencyCount != 0 {
log.Fatal("Agency payload less than 29, len ", AgencyCount)
}
}
Expand Down Expand Up @@ -223,6 +233,10 @@ func (s *Server) RequestRunJobsOfService(ctx context.Context, in *ServiceMessage
in.ServiceUUID,
1,
nil,
UnitMetadata{
Hostname: in.Hostname,
UUID: in.ServiceUUID,
},
})

v.RemapPayload()
Expand Down Expand Up @@ -481,11 +495,12 @@ func (s *Server) HeartBeat(in *ServiceMessage, stream PilotService_HeartBeatServ
ReportDeadService(err.Error(), in.Service)
return err
}
time.Sleep(5 * time.Second)
time.Sleep(1 * time.Second)
}
}
}
}
time.Sleep(5 * time.Second)
}
}

Expand Down
104 changes: 57 additions & 47 deletions service/pilot/grpc/grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions service/pilot/grpc/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ message ServiceMessage {
string Message = 1;
string Service = 2;
string ServiceUUID = 3;
string Hostname = 4;
}


Expand Down
Loading

0 comments on commit 020bc76

Please sign in to comment.