Example #1
0
        public async Task GetBatchAsync_calls_ZendeskApi_IncrementalTicketExport_using_marker()
        {
            await _sut.GetBatchAsync(marker : 123);

            Mock.Get(_zendeskApi).Verify(
                x => x.IncrementalTicketExport(123),
                Times.Once());
        }
Example #2
0
        public async Task RefreshLocalCopyFromServer(bool newDatabase = false)
        {
            var marker = await _markerStorage.GetCurrentMarker();

            VerifyValidConfiguration(newDatabase, marker);

            while (true)
            {
                _log.InfoFormat("Begin copying tickets using marker {0}.", marker.GetValueOrDefault());

                var batch = await _ticketRetriever.GetBatchAsync(marker);

                if (batch.Results.Any())
                {
                    _log.InfoFormat(
                        "Inserting / updating {0} tickets in database retrieved from marker {1}.",
                        batch.Results.Count(),
                        marker.GetValueOrDefault());

                    await _mergeExporter.WriteAsync(batch.Results);
                }

                marker = batch.EndTime;
                await _markerStorage.UpdateCurrentMarker(marker.Value);

                // Terminate when less than MaxItemsReturnedFromZendeskApi returned
                // rather than when zero returned, otherwise could end up in an infinite
                // loop if one or more tickets are created/updated in the course of the
                // _ticketRetriever.GetBatch(marker); cooldown period over and over.
                if (batch.Results.Count() < Configuration.ZendeskMaxItemsReturnedFromTicketExportApi)
                {
                    break;
                }
            }

            _log.Info("Completed copying tickets.");
        }