MCPcopy
hub / github.com/wavetermdev/waveterm / HandleCmdJobExited

Function HandleCmdJobExited

pkg/jobcontroller/jobcontroller.go:864–893  ·  view source on GitHub ↗
(ctx context.Context, jobId string, data wshrpc.CommandJobCmdExitedData)

Source from the content-addressed store, hash-verified

862}
863
864func HandleCmdJobExited(ctx context.Context, jobId string, data wshrpc.CommandJobCmdExitedData) error {
865 var updatedJob *waveobj.Job
866 err := wstore.DBUpdateFn(ctx, jobId, func(job *waveobj.Job) {
867 job.CmdExitError = data.ExitErr
868 job.CmdExitCode = data.ExitCode
869 job.CmdExitSignal = data.ExitSignal
870 job.CmdExitTs = data.ExitTs
871 updatedJob = job
872 })
873 if err != nil {
874 return fmt.Errorf("failed to update job exit status: %w", err)
875 }
876 sendBlockJobStatusEventByJob(ctx, updatedJob)
877 tryTerminateJobManager(ctx, jobId)
878
879 shouldWrite := jobTerminationMessageWritten.TestAndSet(jobId, true, func(val bool, exists bool) bool {
880 return !exists || !val
881 })
882 if shouldWrite {
883 resetTerminalState(ctx, updatedJob.AttachedBlockId)
884 msg := "shell terminated"
885 if updatedJob.CmdExitCode != nil && *updatedJob.CmdExitCode != 0 {
886 msg = fmt.Sprintf("shell terminated (exit code %d)", *updatedJob.CmdExitCode)
887 } else if updatedJob.CmdExitSignal != "" {
888 msg = fmt.Sprintf("shell terminated (signal %s)", updatedJob.CmdExitSignal)
889 }
890 writeMutedMessageToTerminal(updatedJob.AttachedBlockId, "["+msg+"]")
891 }
892 return nil
893}
894
895func tryTerminateJobManager(ctx context.Context, jobId string) {
896 job, err := wstore.DBMustGet[*waveobj.Job](ctx, jobId)

Callers 2

JobCmdExitedCommandMethod · 0.92
restartStreamingFunction · 0.85

Calls 6

DBUpdateFnFunction · 0.92
tryTerminateJobManagerFunction · 0.85
resetTerminalStateFunction · 0.85
TestAndSetMethod · 0.80

Tested by

no test coverage detected