コード例 #1
0
        public Task <IList <PlayerRow> > GetNextPlayerRows(
            int rowLimit, TimeSpan minimumTimeSinceLastSync)
        {
            // Rows are always returned in ascending order by partition key, then row key. A row's row key
            // equals the ticks of the row's last sync time (or a later deprioritized time for players who
            // are probably retired), so this returns the rows most needing a sync.
            string rowKeyCutoff = PlayerRow.GetRowKey(DateTime.UtcNow.Subtract(minimumTimeSinceLastSync));
            var    query        = new TableQuery <PlayerRow>().Where(
                TableQuery.CombineFilters(
                    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "0"),
                    TableOperators.And,
                    TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, rowKeyCutoff)))
                                  .Take(rowLimit);

            return(_playersTable.ExecuteQueryAsync(query));
        }
コード例 #2
0
        public void CreateRequeuedRowForRetiredPlayer()
        {
            var utcNow = DateTime.UtcNow;
            var player = new Player
            {
                ID          = "testte01",
                FeedUrl     = "https://www.basketball-reference.com/players/j/",
                Name        = "test test",
                FirstSeason = 2000,
                LastSeason  = 2010,
            };
            var playerRow = PlayerRow.CreateRow(player, utcNow);

            Assert.AreEqual(playerRow.FirstSeason, playerRow.GetNextSyncSeason());
            Assert.AreEqual(null, playerRow.LastSyncSeason);
            Assert.AreEqual(null, playerRow.LastSyncTimeUtc);
            Assert.AreEqual(null, playerRow.LastSyncWithChangesTimeUtc);
            Assert.AreEqual(PlayerRow.GetRowKey(utcNow), playerRow.RowKey);

            for (int i = 0; i < 10; ++i)
            {
                playerRow = playerRow.CreateRequeuedRow(utcNow.AddTicks(i), playerRow.FirstSeason + i, syncFoundChanges: true);
                Assert.AreEqual(playerRow.FirstSeason + i + 1, playerRow.GetNextSyncSeason());
                Assert.AreEqual(playerRow.FirstSeason + i, playerRow.LastSyncSeason);
                Assert.AreEqual(utcNow.AddTicks(i), playerRow.LastSyncTimeUtc);
                Assert.AreEqual(utcNow.AddTicks(i), playerRow.LastSyncWithChangesTimeUtc);
                Assert.AreEqual(PlayerRow.GetRowKey(utcNow.AddTicks(i)), playerRow.RowKey);
            }

            playerRow = playerRow.CreateRequeuedRow(utcNow.AddTicks(10), playerRow.FirstSeason + 10, syncFoundChanges: true);
            Assert.AreEqual(playerRow.FirstSeason, playerRow.GetNextSyncSeason());
            Assert.AreEqual(playerRow.LastSeason, playerRow.LastSyncSeason);
            Assert.AreEqual(utcNow.AddTicks(10), playerRow.LastSyncTimeUtc);
            Assert.AreEqual(utcNow.AddTicks(10), playerRow.LastSyncWithChangesTimeUtc);
            // Deprioritized due to being retired.
            Assert.AreEqual(PlayerRow.GetRowKey(utcNow.AddTicks(10).AddDays(180)), playerRow.RowKey);
        }