Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching to DateTimeOffset and using nullable=enable. Fixed gitignore #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
# Common IntelliJ Platform excludes

# User specific
**/.idea/**/workspace.xml
**/.idea/**/tasks.xml
**/.idea/shelf/*
**/.idea/dictionaries
**/.idea/httpRequests/

# Sensitive or high-churn files
**/.idea/**/dataSources/
**/.idea/**/dataSources.ids
**/.idea/**/dataSources.xml
**/.idea/**/dataSources.local.xml
**/.idea/**/sqlDataSources.xml
**/.idea/**/dynamic.xml

# Rider
# Rider auto-generates .iml files, and contentModel.xml
**/.idea/**/*.iml
**/.idea/**/contentModel.xml
**/.idea/**/modules.xml

*.suo
*.user
.vs/
[Bb]in/
[Oo]bj/
_UpgradeReport_Files/
[Pp]ackages/

Thumbs.db
Desktop.ini
.DS_Store
2 changes: 1 addition & 1 deletion .idea/.idea.AsyncScheduler/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed .vs/AsyncScheduler/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file removed .vs/AsyncScheduler/v16/.suo
Binary file not shown.
Binary file removed .vs/AsyncScheduler/v16/TestStore/0/003.testlog
Binary file not shown.
Binary file removed .vs/AsyncScheduler/v16/TestStore/0/testlog.manifest
Binary file not shown.
Binary file removed .vs/DotNetAsyncScheduler/v16/.suo
Binary file not shown.
Binary file removed .vs/DotNetAsyncScheduler/v16/TestStore/0/000.testlog
Binary file not shown.
Binary file not shown.
Binary file removed .vs/slnx.sqlite
Binary file not shown.
7 changes: 6 additions & 1 deletion AsyncScheduler.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Prio/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
7 changes: 0 additions & 7 deletions AsyncScheduler.sln.DotSettings.user

This file was deleted.

4 changes: 3 additions & 1 deletion AsyncScheduler/AsyncScheduler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<!-- Optional: Embed source files that are not tracked by the source control manager in the PDB -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IsTestProject>false</IsTestProject>
<Version>0.0.0</Version>
<Version>0.0.0</Version>
<Nullable>enable</Nullable>
<LangVersion>9</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
10 changes: 3 additions & 7 deletions AsyncScheduler/History/IJobHistory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using JetBrains.Annotations;

namespace AsyncScheduler.History
namespace AsyncScheduler.History
{
/// <summary>
/// Interface for accessing the history and results of finished jobs.
Expand All @@ -18,15 +16,13 @@ public interface IJobHistory
/// </summary>
/// <param name="jobKey">key of the job</param>
/// <returns>null, if no finished execution, yet</returns>
[CanBeNull]
IJobHistoryEntry GetLastJobResult(string jobKey);
IJobHistoryEntry? GetLastJobResult(string jobKey);

/// <summary>
/// Retrieve last result of a successful job execution.
/// </summary>
/// <param name="jobKey">key of the job</param>
/// <returns>null, if no successful execution, yet</returns>
[CanBeNull]
IJobHistoryEntry GetLastSuccessfulJobResult(string jobKey);
IJobHistoryEntry? GetLastSuccessfulJobResult(string jobKey);
}
}
2 changes: 1 addition & 1 deletion AsyncScheduler/History/IJobHistoryEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IJobHistoryEntry
/// <summary>
/// Execution time
/// </summary>
DateTime ExecutionTime { get; }
DateTimeOffset ExecutionTime { get; }

/// <summary>
/// Key of the job
Expand Down
15 changes: 6 additions & 9 deletions AsyncScheduler/History/JobHistory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using System.Collections.Generic;

namespace AsyncScheduler.History
{
Expand All @@ -8,26 +7,24 @@ namespace AsyncScheduler.History
/// </summary>
public class JobHistory : IJobHistory
{
private readonly List<IJobHistoryEntry> _jobHistory = new List<IJobHistoryEntry>();
// private readonly List<IJobHistoryEntry> _jobHistory = new();

/// <summary>
/// Last execution for each job
/// </summary>
/// <remarks>Allows efficient access for scheduling</remarks>
private readonly ConcurrentDictionary<string, IJobHistoryEntry> _lastExecutions =
new ConcurrentDictionary<string, IJobHistoryEntry>();
private readonly ConcurrentDictionary<string, IJobHistoryEntry> _lastExecutions = new();

/// <summary>
/// Last successful execution for each job
/// </summary>
/// <remarks>Allows efficient access for scheduling</remarks>
private readonly ConcurrentDictionary<string, IJobHistoryEntry> _lastSuccessfulExecutions =
new ConcurrentDictionary<string, IJobHistoryEntry>();
private readonly ConcurrentDictionary<string, IJobHistoryEntry> _lastSuccessfulExecutions = new();

/// <inheritdoc />
public void Add(IJobHistoryEntry historyEntry)
{
_jobHistory.Add(historyEntry);
// _jobHistory.Add(historyEntry);
_lastExecutions[historyEntry.JobKey] = historyEntry;
if (historyEntry.JobResult == JobResult.Success)
{
Expand All @@ -36,14 +33,14 @@ public void Add(IJobHistoryEntry historyEntry)
}

/// <inheritdoc />
public IJobHistoryEntry GetLastJobResult(string jobKey)
public IJobHistoryEntry? GetLastJobResult(string jobKey)
{
_lastExecutions.TryGetValue(jobKey, out var entry);
return entry;
}

/// <inheritdoc />
public IJobHistoryEntry GetLastSuccessfulJobResult(string jobKey)
public IJobHistoryEntry? GetLastSuccessfulJobResult(string jobKey)
{
_lastSuccessfulExecutions.TryGetValue(jobKey, out var entry);
return entry;
Expand Down
13 changes: 5 additions & 8 deletions AsyncScheduler/History/JobHistoryEntry.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using JetBrains.Annotations;

namespace AsyncScheduler.History
{
/// <inheritdoc />
public class JobHistoryEntry : IJobHistoryEntry
{
public JobHistoryEntry(DateTime executionTime, [NotNull] string jobKey,
JobResult jobResult, object result = null)
public JobHistoryEntry(DateTimeOffset executionTime, string jobKey,
JobResult jobResult, object? result = null)
{
ExecutionTime = executionTime;
JobKey = jobKey ?? throw new ArgumentNullException(nameof(jobKey));
Expand All @@ -16,20 +15,18 @@ public JobHistoryEntry(DateTime executionTime, [NotNull] string jobKey,
}

/// <inheritdoc />
public DateTime ExecutionTime { get; }
public DateTimeOffset ExecutionTime { get; }

/// <inheritdoc />
[NotNull]
public string JobKey { get; }

/// <inheritdoc />
public string ResultString => Result?.ToString();
public string ResultString => Result?.ToString() ?? "null";

/// <summary>
/// Result object returned by task. (Might be used later.)
/// </summary>
[CanBeNull]
public object Result { get; }
public object? Result { get; }

/// <inheritdoc />
public JobResult JobResult { get; }
Expand Down
9 changes: 6 additions & 3 deletions AsyncScheduler/ISchedulerClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ namespace AsyncScheduler
/// </summary>
public interface ISchedulerClock
{
DateTime GetNow();
/// <summary>
/// Returns now
/// </summary>
DateTimeOffset GetNow();
}

/// <summary>
/// Default implementation of clock
/// </summary>
internal class UtcSchedulerClock : ISchedulerClock
{
public DateTime GetNow()
public DateTimeOffset GetNow()
{
return DateTime.UtcNow;
return DateTimeOffset.Now;
}
}
}
15 changes: 7 additions & 8 deletions AsyncScheduler/JobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.ObjectModel;
using AsyncScheduler.JobStorage;
using AsyncScheduler.Schedules;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;

namespace AsyncScheduler
Expand Down Expand Up @@ -30,13 +29,13 @@ public JobManager(IServiceProvider serviceProvider, ILogger<JobManager> logger,
/// <summary>
/// Read access Jobs
/// </summary>
public ReadOnlyDictionary<string, Type> Jobs => new ReadOnlyDictionary<string, Type>(_jobStorage.Jobs);
public ReadOnlyDictionary<string, Type> Jobs => new(_jobStorage.Jobs);

/// <summary>
/// Read access Schedules
/// </summary>
public ReadOnlyDictionary<string, IScheduleProvider> Schedules =>
new ReadOnlyDictionary<string, IScheduleProvider>(_jobStorage.Schedules);
new(_jobStorage.Schedules);

/// <summary>
/// Adds a job.
Expand All @@ -55,7 +54,7 @@ public void AddJob<TJob, TSchedule>() where TJob : IJob where TSchedule : ISched
/// </summary>
/// <param name="schedule">schedule</param>
/// <typeparam name="TJob">Job Type</typeparam>
public void AddJob<TJob>([NotNull] ISchedule schedule) where TJob : IJob
public void AddJob<TJob>(ISchedule schedule) where TJob : IJob
{
AddJob<TJob>(new InstanceScheduleProvider(schedule));
}
Expand All @@ -65,7 +64,7 @@ public void AddJob<TJob>([NotNull] ISchedule schedule) where TJob : IJob
/// </summary>
/// <param name="scheduleProvider">provider/factory for schedule</param>
/// <typeparam name="TJob">job type</typeparam>
public void AddJob<TJob>([NotNull] IScheduleProvider scheduleProvider) where TJob : IJob
public void AddJob<TJob>(IScheduleProvider scheduleProvider) where TJob : IJob
{
AddOrUpdateJobInternal<TJob>(scheduleProvider, false, true);
_logger.LogInformation("Job {jobKey} was added", typeof(TJob));
Expand All @@ -89,7 +88,7 @@ public void UpdateSchedule<TJob, TSchedule>() where TJob : IJob where TSchedule
/// </summary>
/// <param name="schedule">new schedule</param>
/// <typeparam name="TJob">Job Type</typeparam>
public void UpdateSchedule<TJob>([NotNull] ISchedule schedule) where TJob : IJob
public void UpdateSchedule<TJob>(ISchedule schedule) where TJob : IJob
{
UpdateSchedule<TJob>(new InstanceScheduleProvider(schedule));
}
Expand All @@ -99,7 +98,7 @@ public void UpdateSchedule<TJob>([NotNull] ISchedule schedule) where TJob : IJob
/// </summary>
/// <param name="scheduleProvider">new ScheduleProvider</param>
/// <typeparam name="TJob">Job Type</typeparam>
public void UpdateSchedule<TJob>([NotNull] IScheduleProvider scheduleProvider) where TJob : IJob
public void UpdateSchedule<TJob>(IScheduleProvider scheduleProvider) where TJob : IJob
{
AddOrUpdateJobInternal<TJob>(scheduleProvider, true, false);
_logger.LogInformation("Schedule for job {jobKey} was updated", typeof(TJob));
Expand All @@ -110,7 +109,7 @@ public void UpdateSchedule<TJob>([NotNull] IScheduleProvider scheduleProvider) w
/// </summary>
/// <param name="scheduleProvider">ScheduleProvider</param>
/// <typeparam name="TJob">Job Type</typeparam>
public void AddOrUpdate<TJob>([NotNull] IScheduleProvider scheduleProvider) where TJob : IJob
public void AddOrUpdate<TJob>(IScheduleProvider scheduleProvider) where TJob : IJob
{
AddOrUpdateJobInternal<TJob>(scheduleProvider, true, true);
}
Expand Down
17 changes: 12 additions & 5 deletions AsyncScheduler/JobStorage/InMemoryStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@

namespace AsyncScheduler.JobStorage
{
/// <summary>
/// Default storage for holding the Jobs, Schedules etc.
/// It just holds the information in memory.
/// </summary>
public class InMemoryStorage : IJobStorage
{
private readonly ConcurrentDictionary<string, Type> _jobs = new ConcurrentDictionary<string, Type>();
private readonly ConcurrentDictionary<string, Type> _jobs = new();

private readonly ConcurrentDictionary<string, IScheduleProvider> _schedules =
new ConcurrentDictionary<string, IScheduleProvider>();
private readonly ConcurrentDictionary<string, IScheduleProvider> _schedules = new();

/// <inheritdoc />
public IDictionary<string, Type> Jobs => _jobs;

/// <inheritdoc />
public IDictionary<string, IScheduleProvider> Schedules => _schedules;


/// <inheritdoc />
public void AddOrUpdateJobInternal<TJob>(IScheduleProvider scheduleProvider, bool update = false,
bool add = true) where TJob : IJob
{
if (scheduleProvider == null) throw new ArgumentNullException(nameof(scheduleProvider));
var jobType = typeof(TJob);
var jobKey = jobType.FullName ?? throw new NullReferenceException("jobKey");
string jobKey = jobType.FullName ?? throw new NullReferenceException("jobKey");
if (!add && !_jobs.ContainsKey(jobKey))
{
throw new Exception($"No job {jobKey} found for updating");
Expand All @@ -37,9 +43,10 @@ public void AddOrUpdateJobInternal<TJob>(IScheduleProvider scheduleProvider, boo
_schedules[jobKey] = scheduleProvider;
}

/// <inheritdoc />
public bool Remove(string jobKey)
{
var removed = _jobs.TryRemove(jobKey, out _);
bool removed = _jobs.TryRemove(jobKey, out _);
if (!removed)
{
return false;
Expand Down
10 changes: 6 additions & 4 deletions AsyncScheduler/QuickStart/QuickStartRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

namespace AsyncScheduler.QuickStart
{
/// <summary>
/// Quick start allows jobs to be added (e.g. via UI), which are triggered in the next run (when no restrictions apply).
/// A request can be cancelled by the user via cancellationToken.
/// </summary>
internal class QuickStartRequest
{
private readonly CancellationToken _cancellationToken;
Expand All @@ -11,11 +15,11 @@ internal class QuickStartRequest
/// Requested job
/// </summary>
/// <remarks>returns null, if request was cancelled</remarks>
public string JobKey => _cancellationToken.IsCancellationRequested ? null : _jobKey;
public string? JobKey => _cancellationToken.IsCancellationRequested ? null : _jobKey;

private readonly string _jobKey;

private readonly TaskCompletionSource<QuickStartResult> _taskCompletionSource = new TaskCompletionSource<QuickStartResult>();
private readonly TaskCompletionSource<QuickStartResult> _taskCompletionSource = new();

public QuickStartRequest(string jobKey, CancellationToken cancellationToken)
{
Expand All @@ -34,9 +38,7 @@ public QuickStartRequest(string jobKey, CancellationToken cancellationToken)
/// <param name="success">true, when started; false, when not started (e.g. restrictions)</param>
public void MarkExecution(QuickStartResult success)
{
// _executionResult = success;
_taskCompletionSource.SetResult(success);
// _semaphoreResultAvailable.Release();
}
}
}
3 changes: 3 additions & 0 deletions AsyncScheduler/QuickStartResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
/// </summary>
public enum QuickStartResult
{
/// <summary>
/// Default value. Unused.
/// </summary>
Unknown = 0,

/// <summary>
Expand Down
Loading