Example #1
0
        public async Task UpdateRegistrations([TimerTrigger(typeof(EveryWorkingHourSchedule), RunOnStartup = true)]
                                              TimerInfo timer,
                                              ILogger log)
        {
            try
            {
                var filePath = Path.Combine(_SharedBusinessLogic.SharedOptions.DownloadsPath, Filenames.Registrations);

                //Dont execute on startup if file already exists
                if (!StartedJobs.Contains(nameof(UpdateRegistrations)) &&
                    await _SharedBusinessLogic.FileRepository.GetFileExistsAsync(filePath))
                {
                    return;
                }

                await UpdateRegistrationsAsync(log, filePath);

                log.LogDebug($"Executed {nameof(UpdateRegistrations)}:successfully");
            }
            catch (Exception ex)
            {
                var message = $"Failed {nameof(UpdateRegistrations)}:{ex.Message}";

                //Send Email to GEO reporting errors
                await _Messenger.SendGeoMessageAsync("GPG - WEBJOBS ERROR", message);

                //Rethrow the error
                throw;
            }
            finally
            {
                StartedJobs.Add(nameof(UpdateRegistrations));
            }
        }
        public async Task UpdateOrphanOrganisationsAsync([TimerTrigger(typeof(MidnightSchedule), RunOnStartup = true)]
                                                         TimerInfo timer,
                                                         ILogger log)
        {
            var funcName = nameof(UpdateOrphanOrganisationsAsync);

            try
            {
                var filePath = Path.Combine(_SharedBusinessLogic.SharedOptions.DownloadsPath,
                                            Filenames.OrphanOrganisations);

                //Dont execute on startup if file already exists
                if (!StartedJobs.Contains(funcName) &&
                    await _SharedBusinessLogic.FileRepository.GetFileExistsAsync(filePath))
                {
                    log.LogDebug($"Skipped {funcName} at start up.");
                    return;
                }

                // Flag the UpdateUnregisteredOrganisations web job as started
                StartedJobs.Add(funcName);

                await UpdateOrphanOrganisationsAsync(filePath, log);

                log.LogDebug($"Executed {funcName}:successfully");
            }
            catch (Exception ex)
            {
                var message = $"Failed {funcName}:{ex.Message}";

                //Send Email to GEO reporting errors
                await _Messenger.SendGeoMessageAsync("GPG - WEBJOBS ERROR", message);

                //Rethrow the error
                throw;
            }
        }