Skip to content

Commit

Permalink
Merge pull request #43 from Tolyandre/mongo-defaults
Browse files Browse the repository at this point in the history
Conventions should not affect mongodb serialization
  • Loading branch information
Alexander Sidorenko authored Nov 20, 2020
2 parents ac23468 + 78a1d02 commit e46daa4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
37 changes: 34 additions & 3 deletions src/Horarium.Mongo/JobMongoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Horarium.Mongo/MongoRepositoryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion src/Horarium.Mongo/RecurrentJobSettingsMongo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Horarium.Repository;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace Horarium.Mongo
Expand All @@ -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; }
}
}
2 changes: 1 addition & 1 deletion src/Horarium/Interfaces/IRunnerJobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IRunnerJobs

/// <summary>
/// Stops scheduling next jobs and awaits currently running jobs.
/// If <see cref="stopCancellationToken"></see> is cancelled, than abandons running jobs.
/// If <see cref="stopCancellationToken"></see> is cancelled, then abandons running jobs.
/// </summary>
Task Stop(CancellationToken stopCancellationToken);

Expand Down

0 comments on commit e46daa4

Please sign in to comment.