// "DisableConcurrentExecutionAttribute" prevents to start simultaneous job payloads.
        // Should have short timeout, because this attribute implemented by following manner: newly started job falls into "processing" state immediately.
        // Then it tries to receive job lock during timeout. If the lock received, the job starts payload.
        // When the job is awaiting desired timeout for lock release, it stucks in "processing" anyway. (Therefore, you should not to set long timeouts (like 24*60*60), this will cause a lot of stucked jobs and performance degradation.)
        // Then, if timeout is over and the lock NOT acquired, the job falls into "scheduled" state (this is default fail-retry scenario).
        // Failed job goes to "Failed" state (by default) after retries exhausted.
        public async Task Process()
        {
            var criteria = new SubscriptionSearchCriteria
            {
                Statuses = new[] { SubscriptionStatus.Active, SubscriptionStatus.PastDue, SubscriptionStatus.Trialing, SubscriptionStatus.Unpaid }.Select(x => x.ToString()).ToArray(),
                Take     = 0
            };
            var result = await _subscriptionSearchService.SearchSubscriptionsAsync(criteria);

            var batchSize = 20;

            for (var i = 0; i < result.TotalCount; i += batchSize)
            {
                criteria.Skip = i;
                criteria.Take = batchSize;
                result        = await _subscriptionSearchService.SearchSubscriptionsAsync(criteria);

                var subscriptions = await _subscriptionService.GetByIdsAsync(result.Results.Select(x => x.Id).ToArray());

                foreach (var subscription in subscriptions)
                {
                    await _subscriptionBuilder.TakeSubscription(subscription).ActualizeAsync();
                }
                await _subscriptionService.SaveSubscriptionsAsync(subscriptions);
            }
        }
Пример #2
0
        public async Task Process()
        {
            var criteria = new SubscriptionSearchCriteria
            {
                Statuses = new[] { SubscriptionStatus.Active, SubscriptionStatus.PastDue, SubscriptionStatus.Trialing, SubscriptionStatus.Unpaid }.Select(x => x.ToString()).ToArray(),
                Take     = 0,
            };
            var result = await _subscriptionSearchService.SearchSubscriptionsAsync(criteria);

            var batchSize = 20;

            for (var i = 0; i < result.TotalCount; i += batchSize)
            {
                criteria.Skip = i;
                criteria.Take = batchSize;
                result        = await _subscriptionSearchService.SearchSubscriptionsAsync(criteria);

                var subscriptions = await _subscriptionService.GetByIdsAsync(result.Results.Select(x => x.Id).ToArray());

                foreach (var subscription in subscriptions)
                {
                    var subscriptionBuilder = await _subscriptionBuilder.TakeSubscription(subscription).ActualizeAsync();

                    var newOrder = await subscriptionBuilder.TryToCreateRecurrentOrderAsync();

                    if (newOrder != null)
                    {
                        await _customerOrderService.SaveChangesAsync(new[] { newOrder });
                    }
                }
            }
        }
Пример #3
0
        public async Task <IActionResult> SearchSubscriptions([FromBody] SubscriptionSearchCriteria criteria)
        {
            var result = await _subscriptionSearchService.SearchSubscriptionsAsync(criteria);

            var retVal = new SubscriptionSearchResult
            {
                Subscriptions = result.Results.ToList(),
                TotalCount    = result.TotalCount
            };

            return(Ok(retVal));
        }
Пример #4
0
        public async Task DoExportAsync(Stream backupStream, Action <ExportImportProgressInfo> progressCallback,
                                        ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo("Starting data export");

            progressCallback(progressInfo);

            using (var streamWriter = new StreamWriter(backupStream, Encoding.UTF8))
                using (var jsonTextWriter = new JsonTextWriter(streamWriter))
                {
                    await jsonTextWriter.WriteStartObjectAsync();

                    var paymentPlanSearchResponse = await _paymentPlanSearchService.SearchPlansAsync(new PaymentPlanSearchCriteria { Take = 0 });

                    await jsonTextWriter.WritePropertyNameAsync("PaymentPlans");

                    await jsonTextWriter.WriteStartArrayAsync();

                    for (int skip = 0; skip < paymentPlanSearchResponse.TotalCount; skip += BatchSize)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        paymentPlanSearchResponse = await _paymentPlanSearchService.SearchPlansAsync(new PaymentPlanSearchCriteria
                        {
                            Skip = skip,
                            Take = BatchSize
                        });

                        progressInfo.Description = string.Format("{0} of {1} payment plans loading", Math.Min(skip + BatchSize, paymentPlanSearchResponse.TotalCount), paymentPlanSearchResponse.TotalCount);
                        progressCallback(progressInfo);

                        foreach (var paymentPlan in paymentPlanSearchResponse.Results)
                        {
                            _jsonSerializer.Serialize(jsonTextWriter, paymentPlan);
                        }
                    }
                    await jsonTextWriter.WriteEndArrayAsync();

                    var searchResponse = await _subscriptionSearchService.SearchSubscriptionsAsync(new SubscriptionSearchCriteria
                    {
                        Take          = 0,
                        ResponseGroup = SubscriptionResponseGroup.Default.ToString()
                    });

                    await jsonTextWriter.WritePropertyNameAsync("Subscriptions");

                    await jsonTextWriter.WriteStartArrayAsync();

                    for (int skip = 0; skip < searchResponse.TotalCount; skip += BatchSize)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        searchResponse = await _subscriptionSearchService.SearchSubscriptionsAsync(new SubscriptionSearchCriteria
                        {
                            Skip          = skip,
                            Take          = BatchSize,
                            ResponseGroup = SubscriptionResponseGroup.Default.ToString()
                        });

                        progressInfo.Description = string.Format("{0} of {1} subscriptions loading", Math.Min(skip + BatchSize, searchResponse.TotalCount), searchResponse.TotalCount);
                        progressCallback(progressInfo);

                        foreach (var subscription in searchResponse.Results)
                        {
                            _jsonSerializer.Serialize(jsonTextWriter, subscription);
                        }
                    }
                    await jsonTextWriter.WriteEndArrayAsync();

                    await jsonTextWriter.WriteEndObjectAsync();

                    await jsonTextWriter.FlushAsync();
                }
        }
        public async Task <ActionResult <SubscriptionSearchResult> > SearchSubscriptions([FromBody] SubscriptionSearchCriteria criteria)
        {
            var result = await _subscriptionSearchService.SearchSubscriptionsAsync(criteria);

            return(Ok(result));
        }