-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d65a43
commit a4f1e55
Showing
13 changed files
with
812 additions
and
90 deletions.
There are no files selected for viewing
527 changes: 527 additions & 0 deletions
527
src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/Queues/CosmosQueueClient.cs
Large diffs are not rendered by default.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/Queues/IdHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using EnsureThat; | ||
using Microsoft.Health.Core.Extensions; | ||
|
||
namespace Microsoft.Health.Fhir.CosmosDb.Features.Storage.Queues; | ||
|
||
internal static class IdHelper | ||
{ | ||
private const int ShiftFactor = 3; | ||
|
||
internal static readonly DateTime MaxDateTime = new DateTime(long.MaxValue >> ShiftFactor, DateTimeKind.Utc).TruncateToMillisecond().AddTicks(-1); | ||
|
||
public static long DateToId(DateTime dateTime) | ||
{ | ||
EnsureArg.IsLte(dateTime, MaxDateTime, nameof(dateTime)); | ||
long id = dateTime.TruncateToMillisecond().Ticks << ShiftFactor; | ||
|
||
Debug.Assert(id >= 0, "The ID should not have become negative"); | ||
return id; | ||
} | ||
|
||
public static DateTime IdToDate(long resourceSurrogateId) | ||
{ | ||
var dateTime = new DateTime(resourceSurrogateId >> ShiftFactor, DateTimeKind.Utc); | ||
return dateTime.TruncateToMillisecond(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/Queues/JobDefinitionWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.Health.Fhir.CosmosDb.Features.Storage.Queues; | ||
|
||
public class JobDefinitionWrapper | ||
{ | ||
[JsonProperty("jobId")] | ||
public long JobId { get; set; } | ||
|
||
[JsonProperty("status")] | ||
public byte? Status { get; set; } | ||
|
||
[JsonProperty("worker")] | ||
public string Worker { get; set; } | ||
|
||
[JsonProperty("definition")] | ||
public string Definition { get; set; } | ||
|
||
[JsonProperty("definitionHash")] | ||
public string DefinitionHash { get; set; } | ||
|
||
[JsonProperty("result")] | ||
public string Result { get; set; } | ||
|
||
[JsonProperty("data")] | ||
public long? Data { get; set; } | ||
|
||
[JsonProperty("startDate")] | ||
public DateTimeOffset? StartDate { get; set; } | ||
|
||
[JsonProperty("endDate")] | ||
public DateTimeOffset? EndDate { get; set; } | ||
|
||
[JsonProperty("heartbeatDateTime")] | ||
public DateTimeOffset HeartbeatDateTime { get; set; } | ||
|
||
[JsonProperty("cancelRequested")] | ||
public bool CancelRequested { get; set; } | ||
|
||
[JsonProperty("info")] | ||
public string Info { get; set; } | ||
|
||
[JsonProperty("dequeueCount")] | ||
public int DequeueCount { get; set; } | ||
|
||
[JsonProperty("version")] | ||
public long Version { get; set; } | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/Queues/JobGroupWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.Health.Fhir.CosmosDb.Features.Storage.Queues; | ||
|
||
public class JobGroupWrapper : SystemData | ||
{ | ||
public const string JobInfoPartitionKey = "__jobs__"; | ||
|
||
[JsonProperty("groupId")] | ||
public long GroupId { get; set; } | ||
|
||
[JsonProperty(KnownDocumentProperties.PartitionKey)] | ||
public string PartitionKey { get; } = JobInfoPartitionKey; | ||
|
||
[JsonProperty("queueType")] | ||
public byte QueueType { get; set; } | ||
|
||
[JsonProperty("priority")] | ||
public long Priority { get; set; } | ||
|
||
[JsonProperty("definitions")] | ||
public IList<JobDefinitionWrapper> Definitions { get; } = new List<JobDefinitionWrapper>(); | ||
|
||
[JsonProperty("createDate")] | ||
public DateTimeOffset CreateDate { get; set; } | ||
|
||
[JsonProperty("ttl")] | ||
public long TimeToLive { get; set; } | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/Queues/JobInfoExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.Health.JobManagement; | ||
|
||
namespace Microsoft.Health.Fhir.CosmosDb.Features.Storage.Queues; | ||
|
||
public static class JobInfoExtensions | ||
{ | ||
public static IEnumerable<JobInfo> ToJobInfo(this JobGroupWrapper jobGroupWrapper) | ||
{ | ||
return jobGroupWrapper.ToJobInfo(jobGroupWrapper.Definitions); | ||
} | ||
|
||
public static IEnumerable<JobInfo> ToJobInfo(this JobGroupWrapper jobGroupWrapper, IEnumerable<JobDefinitionWrapper> items) | ||
{ | ||
return items.Select(jobInfoWrapperItem => new JobInfo | ||
{ | ||
Id = jobInfoWrapperItem.JobId, | ||
QueueType = jobGroupWrapper.QueueType, | ||
Status = jobInfoWrapperItem.Status.HasValue ? (JobStatus?)jobInfoWrapperItem.Status.Value : null, | ||
GroupId = jobGroupWrapper.GroupId, | ||
Definition = jobInfoWrapperItem.Definition, | ||
Result = jobInfoWrapperItem.Result, | ||
Data = jobInfoWrapperItem.Data, | ||
CancelRequested = jobInfoWrapperItem.CancelRequested, | ||
Priority = jobGroupWrapper.Priority, | ||
CreateDate = jobGroupWrapper.CreateDate.UtcDateTime, | ||
StartDate = jobInfoWrapperItem.StartDate?.UtcDateTime, | ||
EndDate = jobInfoWrapperItem.EndDate?.UtcDateTime, | ||
HeartbeatDateTime = jobInfoWrapperItem.HeartbeatDateTime.UtcDateTime, | ||
Version = jobInfoWrapperItem.Version, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.