public async Task UpdateSyncJobStatusAsync(SyncJob job, SyncStatus status, bool isDryRun, Guid runId)
        {
            await _loggingRepository.LogMessageAsync(new LogMessage { Message = $"Set job status to {status}.", RunId = runId });

            var isDryRunSync = job.IsDryRunEnabled || _isGraphUpdaterDryRunEnabled || isDryRun;

            if (isDryRunSync)
            {
                job.DryRunTimeStamp = DateTime.UtcNow;
            }
            else
            {
                job.LastRunTime = DateTime.UtcNow;
            }

            job.RunId   = runId;
            job.Enabled = status != SyncStatus.Error;

            await _syncJobRepository.UpdateSyncJobStatusAsync(new[] { job }, status);

            string message = isDryRunSync
                                ? $"Dry Run of a sync to {job.TargetOfficeGroupId} is complete. Membership will not be updated."
                                : $"Syncing to {job.TargetOfficeGroupId} done.";

            await _loggingRepository.LogMessageAsync(new LogMessage { Message = message, RunId = runId });
        }
        public async Task Run([ServiceBusTrigger("%serviceBusSyncJobTopic%", "SecurityGroup", Connection = "serviceBusTopicConnection")] Message message,
                              [DurableClient] IDurableOrchestrationClient starter,
                              ILogger log)
        {
            var syncJob = JsonConvert.DeserializeObject <SyncJob>(Encoding.UTF8.GetString(message.Body));
            await _log.LogMessageAsync(new LogMessage { Message = $"{nameof(StarterFunction)} function started", RunId = syncJob.RunId });

            _log.SyncJobProperties = syncJob.ToDictionary();

            if ((DateTime.UtcNow - syncJob.DryRunTimeStamp) < TimeSpan.FromHours(syncJob.Period) && _isSecurityGroupDryRunEnabled == true)
            {
                await _syncJob.UpdateSyncJobStatusAsync(new[] { syncJob }, SyncStatus.Idle);

                await _log.LogMessageAsync(new LogMessage { Message = $"Setting the status of the sync back to Idle as the sync has run within the previous DryRunTimeStamp period", RunId = syncJob.RunId });
            }
            else
            {
                await starter.StartNewAsync(nameof(OrchestratorFunction), syncJob);
            }
            await _log.LogMessageAsync(new LogMessage { Message = $"{nameof(StarterFunction)} function completed", RunId = syncJob.RunId });
        }
 public async Task UpdateSyncJobStatusAsync(SyncJob job, SyncStatus status)
 {
     await _syncJob.UpdateSyncJobStatusAsync(new[] { job }, status);
 }