From 5197c4dfc16f0cbe598df5500c0f1805dc45db02 Mon Sep 17 00:00:00 2001 From: Jordan Jensen Date: Thu, 2 Nov 2023 14:36:27 -0700 Subject: [PATCH 1/2] Separate progress and status events --- internal/logging/logger.go | 3 ++- web/src/api/types/events.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/logging/logger.go b/internal/logging/logger.go index c45286c2b..2adeb9d67 100644 --- a/internal/logging/logger.go +++ b/internal/logging/logger.go @@ -14,6 +14,7 @@ type Phase string const ( StartPhase Phase = "start" ProgressPhase Phase = "progress" + StatusPhase Phase = "status" SuccessPhase Phase = "success" FailurePhase Phase = "failure" LogPhase Phase = "log" @@ -61,7 +62,7 @@ func (l logger) Success(msg string, args ...any) { } func (l logger) Status(msg string, args ...any) { - l.Info(msg, append([]any{LogKeyPhase, ProgressPhase}, args...)...) + l.Info(msg, append([]any{LogKeyPhase, StatusPhase}, args...)...) } func (l logger) Progress(msg string, done float32, total float32, args ...any) { diff --git a/web/src/api/types/events.ts b/web/src/api/types/events.ts index b5f567856..a38ac1f69 100644 --- a/web/src/api/types/events.ts +++ b/web/src/api/types/events.ts @@ -126,6 +126,7 @@ export interface EventSubscriptionTargetCallbackMap { 'publish/restorePythonEnv/start': OnPublishRestorePythonEnvStartCallback 'publish/restorePythonEnv/log': OnPublishRestorePythonEnvLogCallback 'publish/restorePythonEnv/progress': OnPublishRestorePythonEnvProgressCallback + 'publish/restorePythonEnv/status': OnPublishRestorePythonEnvStatusCallback 'publish/restorePythonEnv/success': OnPublishRestorePythonEnvSuccessCallback 'publish/restorePythonEnv/failure': OnPublishRestorePythonEnvFailureCallback // 'publish/restorePythonEnv/failure/serverErr' | // received but temporarily converted @@ -463,6 +464,19 @@ export function isPublishRestorePythonEnvProgress(arg: Events): return arg.type === 'publish/restorePythonEnv/progress'; } +export interface PublishRestorePythonEnvStatus extends EventStreamMessage { + type: 'publish/restorePythonEnv/status', + // structured data not guaranteed, use selective or generic queries + // from data map +} +export type OnPublishRestorePythonEnvStatusCallback = ( + msg: PublishRestorePythonEnvStatus +) => void; +export function isPublishRestorePythonEnvStatus(arg: Events): + arg is PublishRestorePythonEnvStatus { + return arg.type === 'publish/restorePythonEnv/status'; +} + export interface PublishRestorePythonEnvSuccess extends EventStreamMessage { type: 'publish/restorePythonEnv/success', data: { From 669ae7b0bc183450fb810f85b043579172837d79 Mon Sep 17 00:00:00 2001 From: Jordan Jensen Date: Thu, 2 Nov 2023 17:21:00 -0700 Subject: [PATCH 2/2] Fix TestStatus() logger test --- internal/logging/logger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/logging/logger_test.go b/internal/logging/logger_test.go index de43c5ce5..991ddb6be 100644 --- a/internal/logging/logger_test.go +++ b/internal/logging/logger_test.go @@ -53,7 +53,7 @@ func (s *LoggingSuite) TestSuccess() { func (s *LoggingSuite) TestStatus() { baseLogger := NewMockBaseLogger() - baseLogger.On("Info", "message", LogKeyPhase, ProgressPhase, "arg", "value") + baseLogger.On("Info", "message", LogKeyPhase, StatusPhase, "arg", "value") log := logger{baseLogger} log.Status("message", "arg", "value")