Exemple #1
0
        public async Task CanRunNexusUpdateJob()
        {
            var sql = Fixture.GetService <SqlService>();

            var oldRecords = await NexusUpdatesFeeds.GetUpdates();

            foreach (var record in oldRecords)
            {
                await sql.AddNexusModInfo(record.Game, record.ModId, DateTime.UtcNow - TimeSpan.FromDays(1),
                                          new ModInfo());

                await sql.AddNexusModFiles(record.Game, record.ModId, DateTime.UtcNow - TimeSpan.FromDays(1),
                                           new NexusApiClient.GetModFilesResponse());

                Assert.NotNull(await sql.GetModFiles(record.Game, record.ModId));
                Assert.NotNull(await sql.GetNexusModInfoString(record.Game, record.ModId));
            }

            Utils.Log($"Ingested {oldRecords.Count()} nexus records");

            // We know this will load the same records as above, but the date will be more recent, so the above records
            // should no longer exist in SQL after this job is run
            await sql.EnqueueJob(new Job { Payload = new GetNexusUpdatesJob() });

            await RunAllJobs();

            foreach (var record in oldRecords)
            {
                Assert.Null(await sql.GetModFiles(record.Game, record.ModId));
                Assert.Null(await sql.GetNexusModInfoString(record.Game, record.ModId));
            }
        }
Exemple #2
0
        public async Task UpdateNexusCacheRSS()
        {
            using var _ = _logger.BeginScope("Nexus Update via RSS");
            _logger.Log(LogLevel.Information, "Starting");

            var results = await NexusUpdatesFeeds.GetUpdates();

            NexusApiClient client  = null;
            long           updated = 0;

            foreach (var result in results)
            {
                try
                {
                    var purgedMods =
                        await _sql.DeleteNexusModFilesUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                    var purgedFiles =
                        await _sql.DeleteNexusModInfosUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                    var totalPurged = purgedFiles + purgedMods;
                    if (totalPurged > 0)
                    {
                        _logger.Log(LogLevel.Information, $"Purged {totalPurged} cache items {result.Game} {result.ModId} {result.TimeStamp}");
                    }

                    if (await _sql.GetNexusModInfoString(result.Game, result.ModId) != null)
                    {
                        continue;
                    }

                    // Lazily create the client
                    client ??= await NexusApiClient.Get();

                    // Cache the info
                    var files = await client.GetModFiles(result.Game, result.ModId, false);

                    await _sql.AddNexusModFiles(result.Game, result.ModId, result.TimeStamp, files);

                    var modInfo = await client.GetModInfo(result.Game, result.ModId, useCache : false);

                    await _sql.AddNexusModInfo(result.Game, result.ModId, result.TimeStamp, modInfo);

                    updated++;
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, $"Failed Nexus update for {result.Game} - {result.ModId} - {result.TimeStamp}");
                }
            }

            if (updated > 0)
            {
                _logger.Log(LogLevel.Information, $"Primed {updated} nexus cache entries");
            }

            _globalInformation.LastNexusSyncUTC = DateTime.UtcNow;
        }
Exemple #3
0
        public async Task CanGetNexusRSSUpdates()
        {
            var results = (await NexusUpdatesFeeds.GetUpdates()).ToArray();

            Utils.Log($"Loaded {results.Length} updates from the Nexus");

            foreach (var result in results)
            {
                Assert.True(DateTime.UtcNow - result.TimeStamp < TimeSpan.FromDays(1));
            }
        }
Exemple #4
0
        public static async Task <long> UpdateNexusCacheFast(SqlService sql)
        {
            var results = await NexusUpdatesFeeds.GetUpdates();

            NexusApiClient client  = null;
            long           updated = 0;

            foreach (var result in results)
            {
                var purgedMods = await sql.DeleteNexusModFilesUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                var purgedFiles = await sql.DeleteNexusModInfosUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                var totalPurged = purgedFiles + purgedMods;
                if (totalPurged > 0)
                {
                    Utils.Log($"Purged {totalPurged} cache items");
                }

                if (await sql.GetNexusModInfoString(result.Game, result.ModId) != null)
                {
                    continue;
                }

                // Lazily create the client
                client ??= await NexusApiClient.Get();

                // Cache the info
                var files = await client.GetModFiles(result.Game, result.ModId, false);

                await sql.AddNexusModFiles(result.Game, result.ModId, result.TimeStamp, files);

                var modInfo = await client.GetModInfo(result.Game, result.ModId);

                await sql.AddNexusModInfo(result.Game, result.ModId, result.TimeStamp, modInfo);

                updated++;
            }

            if (updated > 0)
            {
                Utils.Log($"Primed {updated} nexus cache entries");
            }

            LastNexusSync = DateTime.Now;
            return(updated);
        }
Exemple #5
0
        public async Task UpdateNexusCacheRSS()
        {
            using var _ = _logger.BeginScope("Nexus Update via RSS");
            _logger.Log(LogLevel.Information, "Starting");

            var results = await NexusUpdatesFeeds.GetUpdates();

            NexusApiClient client  = null;
            long           updated = 0;

            foreach (var result in results)
            {
                try
                {
                    var purgedMods =
                        await _sql.DeleteNexusModFilesUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                    var purgedFiles =
                        await _sql.DeleteNexusModInfosUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                    var totalPurged = purgedFiles + purgedMods;
                    if (totalPurged > 0)
                    {
                        _logger.Log(LogLevel.Information, $"Purged {totalPurged} cache items {result.Game} {result.ModId} {result.TimeStamp}");
                    }

                    updated += totalPurged;
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, $"Failed Nexus update for {result.Game} - {result.ModId} - {result.TimeStamp}");
                }
            }

            if (updated > 0)
            {
                _logger.Log(LogLevel.Information, $"RSS Purged {updated} nexus cache entries");
            }

            _globalInformation.LastNexusSyncUTC = DateTime.UtcNow;
        }