private async Task RecordPeriodEndJob(PeriodEndTaskType taskType, PeriodEndEvent periodEndEvent)
        {
            logger.LogDebug($"Recording period end job. Type: {taskType:G}");
            var generatedMessage = new GeneratedMessage
            {
                MessageId   = periodEndEvent.EventId,
                MessageName = periodEndEvent.GetType().FullName,
                StartTime   = periodEndEvent.EventTime
            };

            if (taskType == PeriodEndTaskType.PeriodEndStart ||
                taskType == PeriodEndTaskType.PeriodEndRun ||
                taskType == PeriodEndTaskType.PeriodEndStop ||
                taskType == PeriodEndTaskType.PeriodEndSubmissionWindowValidation ||
                taskType == PeriodEndTaskType.PeriodEndReports)
            {
                var job = CreatePeriodEndJob(taskType);

                job.JobId             = periodEndEvent.JobId;
                job.CollectionYear    = periodEndEvent.CollectionPeriod.AcademicYear;
                job.CollectionPeriod  = periodEndEvent.CollectionPeriod.Period;
                job.GeneratedMessages = new List <GeneratedMessage> {
                    generatedMessage
                };

                await jobClient.StartPeriodEndJob(job).ConfigureAwait(false);
            }
            else
            {
                throw new InvalidOperationException($"Unhandled period end task type: {taskType:G}");
            }
        }
        private async Task RecordPeriodEndJob(PeriodEndTaskType taskType, PeriodEndEvent periodEndEvent)
        {
            logger.LogDebug($"Recording period end job. Type: {taskType:G}");
            var generatedMessage = new GeneratedMessage
            {
                MessageId   = periodEndEvent.EventId,
                MessageName = periodEndEvent.GetType().FullName,
                StartTime   = periodEndEvent.EventTime
            };

            switch (taskType)
            {
            case PeriodEndTaskType.PeriodEndStart:
                await jobClient.RecordPeriodEndStart(periodEndEvent.JobId, periodEndEvent.CollectionPeriod.AcademicYear,
                                                     periodEndEvent.CollectionPeriod.Period, new List <GeneratedMessage> {
                    generatedMessage
                }).ConfigureAwait(false);

                break;

            case PeriodEndTaskType.PeriodEndRun:
                await jobClient.RecordPeriodEndRun(periodEndEvent.JobId, periodEndEvent.CollectionPeriod.AcademicYear,
                                                   periodEndEvent.CollectionPeriod.Period, new List <GeneratedMessage> {
                    generatedMessage
                }).ConfigureAwait(false);

                break;

            case PeriodEndTaskType.PeriodEndStop:
                await jobClient.RecordPeriodEndStop(periodEndEvent.JobId, periodEndEvent.CollectionPeriod.AcademicYear,
                                                    periodEndEvent.CollectionPeriod.Period, new List <GeneratedMessage> {
                    generatedMessage
                }).ConfigureAwait(false);

                break;

            case PeriodEndTaskType.PeriodEndSubmissionWindowValidation:
                await jobClient.RecordPeriodEndSubmissionWindowValidation(periodEndEvent.JobId, periodEndEvent.CollectionPeriod.AcademicYear,
                                                                          periodEndEvent.CollectionPeriod.Period, new List <GeneratedMessage> {
                    generatedMessage
                }).ConfigureAwait(false);

                break;

            default:
                throw new InvalidOperationException($"Unhandled period end task type: {taskType:G}");
            }
        }