Exemplo n.º 1
0
        public static async Task Run([TimerTrigger("0 0 */4 * * *" /* runs every fourth hour */
#if DEBUG
                                                   , RunOnStartup = true
#endif
                                                   )] TimerInfo myTimer, ILogger log)
        {
            _tmdbApiKey         = Environment.GetEnvironmentVariable("tmdb_api_key");
            _databaseConnection = Environment.GetEnvironmentVariable("database_connection");
            _tmdbService        = new TMDBServiceImpl(_tmdbApiKey, log);

            log.LogInformation($"TMDBDataCollector function started at: {DateTime.Now}");

            List <LocalizationCodes> localizationCodes = GetLocalizationCodes(log);
            await _tmdbService.InitializeAsync();

            if (localizationCodes != null)
            {
                foreach (LocalizationCodes entry in localizationCodes)
                {
                    _tmdbService.Clear();
                    _tmdbSnapshot = await DataCollector.CollectDataAsync(_tmdbService, log, entry.LanguageCode, entry.RegionCode);

                    WriteIntoDatabase(_tmdbSnapshot, log);
                }
            }

            log.LogInformation($"TMDBDataCollector function finished at: {DateTime.Now}");
        }