@@ -18,8 +18,10 @@ import (
18
18
semconv "go.opentelemetry.io/otel/semconv/v1.14.0"
19
19
"go.opentelemetry.io/otel/trace"
20
20
"golang.org/x/xerrors"
21
+ protobuf "google.golang.org/protobuf/proto"
21
22
22
23
"cdr.dev/slog"
24
+ "github.com/coder/coder/v2/codersdk/drpcsdk"
23
25
"github.com/coder/retry"
24
26
25
27
"github.com/coder/coder/v2/coderd/tracing"
@@ -515,7 +517,59 @@ func (p *Server) FailJob(ctx context.Context, in *proto.FailedJob) error {
515
517
return err
516
518
}
517
519
520
+ func (p * Server ) CompleteJobWithModuleFiles (ctx context.Context , in * proto.CompletedJob , moduleFiles []byte ) error {
521
+ return nil
522
+ // Send the files separately if the message size is too large.
523
+ //_, err := clientDoWithRetries(ctx, p.client, func(ctx context.Context, client proto.DRPCProvisionerDaemonClient) (*proto.Empty, error) {
524
+ // stream, err := client.CompleteJobWithFiles(ctx)
525
+ // if err != nil {
526
+ // return nil, xerrors.Errorf("failed to start CompleteJobWithFiles stream: %w", err)
527
+ // }
528
+ //
529
+ // dataUp, chunks := sdkproto.BytesToDataUpload(moduleFiles)
530
+ //
531
+ // err = stream.Send(&proto.CompleteWithFilesRequest{Type: &proto.CompleteWithFilesRequest_DataUpload{DataUpload: &proto.DataUpload{
532
+ // UploadType: proto.DataUploadType(dataUp.UploadType),
533
+ // DataHash: dataUp.DataHash,
534
+ // FileSize: dataUp.FileSize,
535
+ // Chunks: dataUp.Chunks,
536
+ // }}})
537
+ // if err != nil {
538
+ // return nil, xerrors.Errorf("send data upload: %w", err)
539
+ // }
540
+ //
541
+ // for i, chunk := range chunks {
542
+ // err = stream.Send(&proto.CompleteWithFilesRequest{Type: &proto.CompleteWithFilesRequest_ChunkPiece{ChunkPiece: &proto.ChunkPiece{
543
+ // Data: chunk.Data,
544
+ // FullDataHash: chunk.FullDataHash,
545
+ // PieceIndex: chunk.PieceIndex,
546
+ // }}})
547
+ // if err != nil {
548
+ // return nil, xerrors.Errorf("send chunk piece %d: %w", i, err)
549
+ // }
550
+ // }
551
+ //
552
+ // err = stream.Send(&proto.CompleteWithFilesRequest{Type: &proto.CompleteWithFilesRequest_Complete{Complete: in}})
553
+ // if err != nil {
554
+ // return nil, xerrors.Errorf("send complete job: %w", err)
555
+ // }
556
+ //
557
+ // return &proto.Empty{}, nil
558
+ //})
559
+ //return err
560
+ }
561
+
518
562
func (p * Server ) CompleteJob (ctx context.Context , in * proto.CompletedJob ) error {
563
+ if ti , ok := in .Type .(* proto.CompletedJob_TemplateImport_ ); ok {
564
+ messageSize := protobuf .Size (in )
565
+ if messageSize > drpcsdk .MaxMessageSize &&
566
+ messageSize - len (ti .TemplateImport .ModuleFiles ) < drpcsdk .MaxMessageSize {
567
+ moduleFiles := ti .TemplateImport .ModuleFiles
568
+ ti .TemplateImport .ModuleFiles = nil // Clear the files in the final message
569
+ return p .CompleteJobWithModuleFiles (ctx , in , moduleFiles )
570
+ }
571
+ }
572
+
519
573
_ , err := clientDoWithRetries (ctx , p .client , func (ctx context.Context , client proto.DRPCProvisionerDaemonClient ) (* proto.Empty , error ) {
520
574
return client .CompleteJob (ctx , in )
521
575
})
0 commit comments