Skip to content

Commit

Permalink
Add timestamps to Preservation tasks
Browse files Browse the repository at this point in the history
adds timestamps to Preservations Tasks and gives additional details to the user in the enduro dashboard about when archivematica jobs started and finished.

Closes #832
  • Loading branch information
Diogenesoftoronto committed Jan 25, 2024
1 parent 63cb14f commit 533b581
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 17 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/go-sql-driver/mysql v1.7.1
github.com/golang-migrate/migrate/v4 v4.17.0
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.5.0
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.1
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/jmoiron/sqlx v1.3.5
Expand All @@ -39,7 +39,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
go.artefactual.dev/amclient v0.2.0
go.artefactual.dev/amclient v0.3.0
go.artefactual.dev/tools v0.8.0
go.opentelemetry.io/otel v1.21.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/wire v0.5.0 h1:I7ELFeVBr3yfPIcc8+MWvrjk+3VjbcSzoXm3JVa+jD8=
github.com/google/wire v0.5.0/go.mod h1:ngWDr9Qvq3yZA10YrxfyGELY/AFWGVpy9c1LTRi1EoU=
github.com/googleapis/enterprise-certificate-proxy v0.0.0-20220520183353-fd19c99a87aa/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8=
Expand Down Expand Up @@ -1372,6 +1374,8 @@ github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
go.artefactual.dev/amclient v0.2.0 h1:fO1lUsxaG23EGtbgPBfye5+ytnqg3H7BxAoAaQr0Mqc=
go.artefactual.dev/amclient v0.2.0/go.mod h1:jAJ98cSJ7QDSgMq/YUkmGpAJ4ssSzbIUN7XpynCa6uA=
go.artefactual.dev/amclient v0.3.0 h1:biXZobSWJCzwpJOYtlQzOkClOv2u5mB1TKA4023B7zw=
go.artefactual.dev/amclient v0.3.0/go.mod h1:jAJ98cSJ7QDSgMq/YUkmGpAJ4ssSzbIUN7XpynCa6uA=
go.artefactual.dev/tools v0.8.0 h1:PYmurlVFIA5hA2p/lX4wq+sHkIhezN8kCpiBDT0NaFA=
go.artefactual.dev/tools v0.8.0/go.mod h1:tBZMFxz4jkQK5MW+uDROYaAkTGQSG0lJgCVhqDbQ1Dg=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
Expand Down
37 changes: 33 additions & 4 deletions internal/am/job_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ func (jt *JobTracker) SavePreservationTasks(ctx context.Context, unitID string)

// list requests a job list for unitID from the Archivematica jobs endpoint.
func (jt *JobTracker) list(ctx context.Context, unitID string) ([]amclient.Job, error) {
jobs, httpResp, err := jt.jobSvc.List(ctx, unitID, &amclient.JobsListRequest{})
jobs, httpResp, err := jt.jobSvc.List(ctx, unitID, &amclient.JobsListRequest{
Detailed: true,
})
if err != nil {
return nil, convertAMClientError(httpResp, err)
}
Expand Down Expand Up @@ -115,9 +117,36 @@ func filterSavedJobs(jobs []amclient.Job, saved map[string]struct{}) []amclient.
// ConvertJobToPreservationTask converts an amclient.Job to a
// package_.PreservationTask.
func ConvertJobToPreservationTask(job amclient.Job) package_.PreservationTask {
st, co := getJobTimestamp(job)
return package_.PreservationTask{
TaskID: job.ID,
Name: job.Name,
Status: jobStatusToPreservationTaskStatus[job.Status],
TaskID: job.ID,
Name: job.Name,
Status: jobStatusToPreservationTaskStatus[job.Status],
StartedAt: st,
CompletedAt: co,
}
}

func getJobTimestamp(job amclient.Job) (sql.NullTime, sql.NullTime) {
st := job.Tasks[0].StartedAt.Time
ct := job.Tasks[0].CompletedAt.Time

for _, t := range job.Tasks {
// if current st is after the task time set that as the startedat time.
if st.After(t.StartedAt.Time) {
st = t.StartedAt.Time
}
// if current co is before the task time set that as the completedat time.
if ct.Before(t.CompletedAt.Time) {
ct = t.CompletedAt.Time
}
}

return sql.NullTime{
Time: st,
Valid: true,
}, sql.NullTime{
Time: ct,
Valid: true,
}
}
12 changes: 9 additions & 3 deletions internal/am/job_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func TestJobTracker(t *testing.T) {
m.List(
mockutil.Context(),
unitID,
&amclient.JobsListRequest{},
&amclient.JobsListRequest{
Detailed: true,
},
).Return(
nil,
&amclient.Response{Response: &http.Response{StatusCode: statusCode}},
Expand Down Expand Up @@ -85,7 +87,9 @@ func TestJobTracker(t *testing.T) {
m.List(
mockutil.Context(),
unitID,
&amclient.JobsListRequest{},
&amclient.JobsListRequest{
Detailed: true,
},
).Return(
jobs,
&amclient.Response{
Expand Down Expand Up @@ -113,7 +117,9 @@ func TestJobTracker(t *testing.T) {
m.List(
mockutil.Context(),
unitID,
&amclient.JobsListRequest{},
&amclient.JobsListRequest{
Detailed: true,
},
).Return(
nil,
&amclient.Response{
Expand Down
8 changes: 6 additions & 2 deletions internal/am/poll_ingest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ func TestPollIngestActivity(t *testing.T) {
m.List(
mockutil.Context(),
sipID,
&amclient.JobsListRequest{},
&amclient.JobsListRequest{
Detailed: true,
},
).Return(
jobs[:1],
&amclient.Response{Response: &http200Resp},
Expand All @@ -138,7 +140,9 @@ func TestPollIngestActivity(t *testing.T) {
m.List(
mockutil.Context(),
sipID,
&amclient.JobsListRequest{},
&amclient.JobsListRequest{
Detailed: true,
},
).Return(
jobs,
&amclient.Response{Response: &http200Resp},
Expand Down
27 changes: 21 additions & 6 deletions internal/am/poll_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ func TestPollTransferActivity(t *testing.T) {
LinkID: "541f5994-73b0-45bb-9cb5-367c06a21be7",
Tasks: []amclient.Task{
{
ID: "11566538-66c5-4a20-aa70-77f7a9fa83d5",
ExitCode: 0,
ID: "11566538-66c5-4a20-aa70-77f7a9fa83d5",
ExitCode: 0,
Filename: "Images-94ade01c-49ce-49e0-9cc3-805575c676d0",
CreatedAt: amclient.TaskDateTime{Time: time.Date(2024, time.January, 18, 1, 27, 49, 0, time.UTC)},
StartedAt: amclient.TaskDateTime{Time: time.Date(2024, time.January, 18, 1, 27, 49, 0, time.UTC)},
CompletedAt: amclient.TaskDateTime{Time: time.Date(2024, time.January, 18, 1, 27, 49, 0, time.UTC)},
Duration: amclient.TaskDuration(time.Second / 2),
},
},
},
Expand All @@ -62,8 +67,14 @@ func TestPollTransferActivity(t *testing.T) {
LinkID: "045c43ae-d6cf-44f7-97d6-c8a602748565",
Tasks: []amclient.Task{
{
ID: "53666170-0397-4962-8736-23295444b036",
ExitCode: 0,
ID: "53666170-0397-4962-8736-23295444b036",
ExitCode: 0,
FileID: "",
Filename: "Images-94ade01c-49ce-49e0-9cc3-805575c676d0",
CreatedAt: amclient.TaskDateTime{Time: time.Date(2024, time.January, 18, 1, 27, 49, 0, time.UTC)},
StartedAt: amclient.TaskDateTime{Time: time.Date(2024, time.January, 18, 1, 27, 49, 0, time.UTC)},
CompletedAt: amclient.TaskDateTime{Time: time.Date(2024, time.January, 18, 1, 27, 49, 0, time.UTC)},
Duration: amclient.TaskDuration(time.Second / 2),
},
},
},
Expand Down Expand Up @@ -124,7 +135,9 @@ func TestPollTransferActivity(t *testing.T) {
m.List(
mockutil.Context(),
transferID,
&amclient.JobsListRequest{},
&amclient.JobsListRequest{
Detailed: true,
},
).Return(
jobs,
&amclient.Response{Response: &http200Resp},
Expand All @@ -136,7 +149,9 @@ func TestPollTransferActivity(t *testing.T) {
m.List(
mockutil.Context(),
transferID,
&amclient.JobsListRequest{},
&amclient.JobsListRequest{
Detailed: true,
},
).Return(
jobs,
&amclient.Response{Response: &http200Resp},
Expand Down

0 comments on commit 533b581

Please sign in to comment.