|
| 1 | +// This file is part of the ArmoniK project |
| 2 | +// |
| 3 | +// Copyright (C) ANEO, 2021-2023. All rights reserved. |
| 4 | +// |
| 5 | +// This program is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU Affero General Public License as published |
| 7 | +// by the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// This program is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY, without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU Affero General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU Affero General Public License |
| 16 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +using ArmoniK.Api.gRPC.V1; |
| 19 | +using ArmoniK.Api.gRPC.V1.Tasks; |
| 20 | + |
| 21 | +using Google.Protobuf.WellKnownTypes; |
| 22 | + |
| 23 | +using static Google.Protobuf.WellKnownTypes.Timestamp; |
| 24 | + |
| 25 | +namespace ArmoniK.Core.Common.Storage; |
| 26 | + |
| 27 | +public static class TaskDataSummaryExt |
| 28 | +{ |
| 29 | + /// <summary> |
| 30 | + /// Conversion operator from <see cref="TaskDataSummary" /> to gRPC <see cref="TaskSummary" /> |
| 31 | + /// </summary> |
| 32 | + /// <param name="taskDataSummary">The input task data</param> |
| 33 | + /// <returns> |
| 34 | + /// The converted task data |
| 35 | + /// </returns> |
| 36 | + public static TaskSummary ToTaskSummary(this TaskDataSummary taskDataSummary) |
| 37 | + => new() |
| 38 | + { |
| 39 | + SessionId = taskDataSummary.SessionId, |
| 40 | + Status = taskDataSummary.Status, |
| 41 | + OwnerPodId = taskDataSummary.OwnerPodId, |
| 42 | + Options = taskDataSummary.Options.ToGrpcTaskOptions(), |
| 43 | + CreatedAt = FromDateTime(taskDataSummary.CreationDate), |
| 44 | + EndedAt = taskDataSummary.EndDate is not null |
| 45 | + ? FromDateTime(taskDataSummary.EndDate.Value) |
| 46 | + : null, |
| 47 | + Id = taskDataSummary.TaskId, |
| 48 | + PodTtl = taskDataSummary.PodTtl is not null |
| 49 | + ? FromDateTime(taskDataSummary.PodTtl.Value) |
| 50 | + : null, |
| 51 | + StartedAt = taskDataSummary.StartDate is not null |
| 52 | + ? FromDateTime(taskDataSummary.StartDate.Value) |
| 53 | + : null, |
| 54 | + Error = taskDataSummary.Status == TaskStatus.Error |
| 55 | + ? taskDataSummary.Output.Error |
| 56 | + : "", |
| 57 | + StatusMessage = taskDataSummary.StatusMessage, |
| 58 | + SubmittedAt = taskDataSummary.SubmittedDate is not null |
| 59 | + ? FromDateTime(taskDataSummary.SubmittedDate.Value) |
| 60 | + : null, |
| 61 | + AcquiredAt = taskDataSummary.AcquisitionDate is not null |
| 62 | + ? FromDateTime(taskDataSummary.AcquisitionDate.Value) |
| 63 | + : null, |
| 64 | + ReceivedAt = taskDataSummary.ReceptionDate is not null |
| 65 | + ? FromDateTime(taskDataSummary.ReceptionDate.Value) |
| 66 | + : null, |
| 67 | + PodHostname = taskDataSummary.OwnerPodName, |
| 68 | + CreationToEndDuration = taskDataSummary.CreationToEndDuration is not null |
| 69 | + ? Duration.FromTimeSpan(taskDataSummary.CreationToEndDuration.Value) |
| 70 | + : null, |
| 71 | + ProcessingToEndDuration = taskDataSummary.ProcessingToEndDuration is not null |
| 72 | + ? Duration.FromTimeSpan(taskDataSummary.ProcessingToEndDuration.Value) |
| 73 | + : null, |
| 74 | + InitialTaskId = taskDataSummary.InitialTaskId, |
| 75 | + CountDataDependencies = taskDataSummary.DataDependenciesCount, |
| 76 | + CountExpectedOutputIds = taskDataSummary.ExpectedOutputIdsCount, |
| 77 | + CountParentTaskIds = taskDataSummary.ParentTaskIdsCount, |
| 78 | + CountRetryOfIds = taskDataSummary.RetryOfIdsCount, |
| 79 | + }; |
| 80 | +} |
0 commit comments