From 317d6eb4d91ad978e03c973e6a1fe65fd082daf1 Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Mon, 24 Apr 2023 12:05:01 +0200 Subject: [PATCH] Add updated_at field in process infos --- http/api/process.go | 1 + http/handler/api/restream.go | 1 + restream/app/process.go | 2 ++ restream/restream.go | 5 +++++ restream/restream_test.go | 13 ++++++++++++- 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/http/api/process.go b/http/api/process.go index e217b455..d52d4393 100644 --- a/http/api/process.go +++ b/http/api/process.go @@ -14,6 +14,7 @@ type Process struct { Type string `json:"type" jsonschema:"enum=ffmpeg"` Reference string `json:"reference"` CreatedAt int64 `json:"created_at" jsonschema:"minimum=0" format:"int64"` + UpdatedAt int64 `json:"updated_at" jsonschema:"minimum=0" format:"int64"` Config *ProcessConfig `json:"config,omitempty"` State *ProcessState `json:"state,omitempty"` Report *ProcessReport `json:"report,omitempty"` diff --git a/http/handler/api/restream.go b/http/handler/api/restream.go index c61f363a..96a4f75c 100644 --- a/http/handler/api/restream.go +++ b/http/handler/api/restream.go @@ -544,6 +544,7 @@ func (h *RestreamHandler) getProcess(id, filterString string) (api.Process, erro Reference: process.Reference, Type: "ffmpeg", CreatedAt: process.CreatedAt, + UpdatedAt: process.UpdatedAt, } if wants["config"] { diff --git a/restream/app/process.go b/restream/app/process.go index 4ec6036a..5e301c39 100644 --- a/restream/app/process.go +++ b/restream/app/process.go @@ -106,6 +106,7 @@ type Process struct { Reference string `json:"reference"` Config *Config `json:"config"` CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` Order string `json:"order"` } @@ -115,6 +116,7 @@ func (process *Process) Clone() *Process { Reference: process.Reference, Config: process.Config.Clone(), CreatedAt: process.CreatedAt, + UpdatedAt: process.UpdatedAt, Order: process.Order, } diff --git a/restream/restream.go b/restream/restream.go index 597a2e0a..bd5e1482 100644 --- a/restream/restream.go +++ b/restream/restream.go @@ -456,6 +456,8 @@ func (r *restream) createTask(config *app.Config) (*task, error) { CreatedAt: time.Now().Unix(), } + process.UpdatedAt = process.CreatedAt + if config.Autostart { process.Order = "start" } @@ -867,6 +869,9 @@ func (r *restream) UpdateProcess(id string, config *app.Config) error { return ErrUnknownProcess } + // This would require a major version jump + //t.process.CreatedAt = task.process.CreatedAt + t.process.UpdatedAt = time.Now().Unix() task.parser.TransferReportHistory(t.parser) t.process.Order = task.process.Order diff --git a/restream/restream_test.go b/restream/restream_test.go index a0d782b0..208e30b0 100644 --- a/restream/restream_test.go +++ b/restream/restream_test.go @@ -216,6 +216,14 @@ func TestUpdateProcess(t *testing.T) { err = rs.AddProcess(process2) require.Equal(t, nil, err) + process, err := rs.GetProcess(process2.ID) + require.NoError(t, err) + + //createdAt := process.CreatedAt + updatedAt := process.UpdatedAt + + time.Sleep(2 * time.Second) + process3 := getDummyProcess() require.NotNil(t, process3) process3.ID = "process2" @@ -230,8 +238,11 @@ func TestUpdateProcess(t *testing.T) { _, err = rs.GetProcess(process1.ID) require.Error(t, err) - _, err = rs.GetProcess(process3.ID) + process, err = rs.GetProcess(process3.ID) require.NoError(t, err) + + //require.Equal(t, createdAt, process.CreatedAt) + require.NotEqual(t, updatedAt, process.UpdatedAt) } func TestGetProcess(t *testing.T) {