@@ -2,14 +2,14 @@ package server
22
33import (
44 "context"
5- "fmt"
6- "time"
75
86 "github.com/pkg/errors"
97
108 template_manager "github.com/e2b-dev/infra/packages/shared/pkg/grpc/template-manager"
119)
1210
11+ const maxLogEntriesPerRequest = int32 (100 )
12+
1313func (s * ServerStore ) TemplateBuildStatus (ctx context.Context , in * template_manager.TemplateStatusRequest ) (* template_manager.TemplateBuildStatusResponse , error ) {
1414 _ , ctxSpan := tracer .Start (ctx , "template-build-status-request" )
1515 defer ctxSpan .End ()
@@ -19,7 +19,11 @@ func (s *ServerStore) TemplateBuildStatus(ctx context.Context, in *template_mana
1919 return nil , errors .Wrap (err , "error while getting build info, maybe already expired" )
2020 }
2121
22- logs := make ([]string , 0 )
22+ limit := maxLogEntriesPerRequest
23+ if in .Limit != nil && in .GetLimit () < int32 (maxLogEntriesPerRequest ) {
24+ limit = in .GetLimit ()
25+ }
26+
2327 logEntries := make ([]* template_manager.TemplateBuildLogEntry , 0 )
2428 logsCrawled := int32 (0 )
2529 for _ , entry := range buildInfo .GetLogs () {
@@ -33,8 +37,11 @@ func (s *ServerStore) TemplateBuildStatus(ctx context.Context, in *template_mana
3337 continue
3438 }
3539
40+ if int32 (len (logEntries )) >= limit {
41+ break
42+ }
43+
3644 logEntries = append (logEntries , entry )
37- logs = append (logs , fmt .Sprintf ("[%s] %s" , entry .GetTimestamp ().AsTime ().Format (time .RFC3339 ), entry .GetMessage ()))
3845 }
3946
4047 result := buildInfo .GetResult ()
@@ -43,7 +50,6 @@ func (s *ServerStore) TemplateBuildStatus(ctx context.Context, in *template_mana
4350 Status : template_manager .TemplateBuildState_Building ,
4451 Reason : nil ,
4552 Metadata : nil ,
46- Logs : logs ,
4753 LogEntries : logEntries ,
4854 }, nil
4955 }
@@ -52,7 +58,6 @@ func (s *ServerStore) TemplateBuildStatus(ctx context.Context, in *template_mana
5258 Status : result .Status ,
5359 Reason : result .Reason ,
5460 Metadata : result .Metadata ,
55- Logs : logs ,
5661 LogEntries : logEntries ,
5762 }, nil
5863}
0 commit comments