Skip to content

Commit

Permalink
Add warning if no jobs configured (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead authored Dec 14, 2022
1 parent 34536c8 commit fdc152d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ private async Task<ProcessGlobalChangeTrackingResult> ProcessSchedule(
}

var expires = DateTimeOffset.UtcNow.AddMinutes(4);
ICollection<SyncJobConfig> values = SyncJobsConfig?.Value?.Jobs?.Values;
var tokenCache = await TokenCacheService.GetTokenCache(values ?? Array.Empty<SyncJobConfig>());
var values = SyncJobsConfig?.Value?.Jobs?.Values;

if (values == null || values.Count == 0)
{
Logger.LogWarning("{Config} no jobs configured, skipping.", config);
return ProcessGlobalChangeTrackingResult.Empty;
}

var tokenCache = await TokenCacheService.GetTokenCache(values);

var syncJobs = SyncJobsConfig
.Value
Expand Down
5 changes: 3 additions & 2 deletions src/SqlBulkSyncFunction/Models/Job/SyncJobsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ public record SyncJobsConfig
{
private static readonly string[] DefaultJobSchedules = {"Custom"};

public Dictionary<string, SyncJobConfig> Jobs { get; init; }
public Dictionary<string, SyncJobConfig> Jobs { get; init; }

public Lazy<ILookup<string, (string Key, SyncJobConfig Job)>> ScheduledJobs { get; }
private static Dictionary<string, SyncJobConfig> Empty { get; } = new Dictionary<string, SyncJobConfig>(0);

private ILookup<string, (string Key, SyncJobConfig Job)> GetScheduledJobs()
=> (
from job in Jobs
from job in Jobs ?? Empty
where !job.Value.Manual.HasValue || job.Value.Manual == false
from schedule in GetJobSchedules(job)
select (Key: schedule, job.Value)
Expand Down

0 comments on commit fdc152d

Please sign in to comment.