From 526a4f3cfb15719d921b482f1d7e08329808f05f Mon Sep 17 00:00:00 2001 From: Anatoly Buranov <2414704+Tolyandre@users.noreply.github.com> Date: Tue, 17 Nov 2020 10:48:30 +0400 Subject: [PATCH 1/2] Fix typo and parameters order --- src/Horarium.Mongo/MongoRepositoryFactory.cs | 4 ++-- src/Horarium/Interfaces/IRunnerJobs.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Horarium.Mongo/MongoRepositoryFactory.cs b/src/Horarium.Mongo/MongoRepositoryFactory.cs index 3ed5c5a..c0d1ddc 100644 --- a/src/Horarium.Mongo/MongoRepositoryFactory.cs +++ b/src/Horarium.Mongo/MongoRepositoryFactory.cs @@ -9,7 +9,7 @@ public static class MongoRepositoryFactory public static IJobRepository Create(string connectionString) { if (string.IsNullOrEmpty(connectionString)) - throw new ArgumentNullException("Connections string is empty"); + throw new ArgumentNullException(nameof(connectionString), "Connection string is empty"); var provider = new MongoClientProvider(connectionString); return new MongoRepository(provider); @@ -18,7 +18,7 @@ public static IJobRepository Create(string connectionString) public static IJobRepository Create(MongoUrl mongoUrl) { if (mongoUrl == null) - throw new ArgumentNullException("Connections string is empty"); + throw new ArgumentNullException(nameof(mongoUrl), "mongoUrl is null"); var provider = new MongoClientProvider(mongoUrl); return new MongoRepository(provider); diff --git a/src/Horarium/Interfaces/IRunnerJobs.cs b/src/Horarium/Interfaces/IRunnerJobs.cs index 804bc09..c831c00 100644 --- a/src/Horarium/Interfaces/IRunnerJobs.cs +++ b/src/Horarium/Interfaces/IRunnerJobs.cs @@ -9,7 +9,7 @@ public interface IRunnerJobs /// /// Stops scheduling next jobs and awaits currently running jobs. - /// If is cancelled, than abandons running jobs. + /// If is cancelled, then abandons running jobs. /// Task Stop(CancellationToken stopCancellationToken); From 78a1d0237bb8d34ad51c662ca96f22623e7bd174 Mon Sep 17 00:00:00 2001 From: Anatoly Buranov <2414704+Tolyandre@users.noreply.github.com> Date: Tue, 17 Nov 2020 11:05:20 +0400 Subject: [PATCH 2/2] Global conventions (eg from class ConventionRegistry) shall not affect Horarium mongodb serialization. Mongodb fields and types are explicit now. --- src/Horarium.Mongo/JobMongoModel.cs | 37 +++++++++++++++++-- .../RecurrentJobSettingsMongo.cs | 8 +++- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/Horarium.Mongo/JobMongoModel.cs b/src/Horarium.Mongo/JobMongoModel.cs index a8d438b..99070c6 100644 --- a/src/Horarium.Mongo/JobMongoModel.cs +++ b/src/Horarium.Mongo/JobMongoModel.cs @@ -32,40 +32,71 @@ public JobDb ToJobDb() }; } - [BsonId] + [BsonId] + [BsonRepresentation(BsonType.String)] public string JobId { get; set; } + [BsonRepresentation(BsonType.String)] + [BsonElement("JobKey")] public string JobKey { get; set; } + [BsonRepresentation(BsonType.String)] + [BsonElement("JobType")] public string JobType { get; set; } + [BsonRepresentation(BsonType.String)] + [BsonElement("JobParamType")] public string JobParamType { get; set; } + [BsonRepresentation(BsonType.String)] + [BsonElement("JobParam")] public string JobParam { get; set; } + [BsonRepresentation(BsonType.Int32)] + [BsonElement("Status")] public JobStatus Status { get; set; } + [BsonRepresentation(BsonType.Int32)] + [BsonElement("CountStarted")] public int CountStarted { get; set; } + [BsonRepresentation(BsonType.String)] + [BsonElement("ExecutedMachine")] public string ExecutedMachine { get; set; } + [BsonDateTimeOptions(Kind = DateTimeKind.Utc, DateOnly = false, Representation = BsonType.DateTime)] + [BsonElement("StartedExecuting")] public DateTime StartedExecuting { get; set; } + [BsonDateTimeOptions(Kind = DateTimeKind.Utc, DateOnly = false, Representation = BsonType.DateTime)] + [BsonElement("StartAt")] public DateTime StartAt { get; set; } + [BsonElement("NextJob")] public JobMongoModel NextJob { get; set; } + [BsonRepresentation(BsonType.String)] + [BsonElement("Error")] public string Error { get; set; } + [BsonRepresentation(BsonType.String)] + [BsonElement("Cron")] public string Cron { get; set; } + [BsonTimeSpanOptions(BsonType.String)] + [BsonElement("Delay")] public TimeSpan? Delay { get; set; } [BsonTimeSpanOptions(BsonType.Int64, TimeSpanUnits.Milliseconds)] + [BsonElement("ObsoleteInterval")] public TimeSpan ObsoleteInterval { get; set; } - + + [BsonRepresentation(BsonType.String)] + [BsonElement("RepeatStrategy")] public string RepeatStrategy { get; set; } - + + [BsonRepresentation(BsonType.Int32)] + [BsonElement("MaxRepeatCount")] public int MaxRepeatCount { get; set; } public static JobMongoModel CreateJobMongoModel(JobDb jobDb) diff --git a/src/Horarium.Mongo/RecurrentJobSettingsMongo.cs b/src/Horarium.Mongo/RecurrentJobSettingsMongo.cs index 99f9933..1b00c78 100644 --- a/src/Horarium.Mongo/RecurrentJobSettingsMongo.cs +++ b/src/Horarium.Mongo/RecurrentJobSettingsMongo.cs @@ -1,4 +1,5 @@ using Horarium.Repository; +using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; namespace Horarium.Mongo @@ -17,10 +18,15 @@ public static RecurrentJobSettingsMongo Create(RecurrentJobSettings jobSettings) } [BsonId] + [BsonRepresentation(BsonType.String)] public string JobKey { get; private set; } + [BsonRepresentation(BsonType.String)] + [BsonElement("JobType")] public string JobType { get; private set; } - + + [BsonRepresentation(BsonType.String)] + [BsonElement("Cron")] public string Cron { get; private set; } } }