Ejemplo n.º 1
0
        public async Task <string> AcquireNextAccountForPullingReportAsync(string processor)
        {
            // Get all accounts with no processor
            var idleAccounts = await ReportLeaseTableEntity.ListAsync(reportLeaseTable, null);

            if (idleAccounts == null || idleAccounts.Count <= 0)
            {
                return(null);
            }

            // Try to acquire one and only one account
            var now = DateTime.UtcNow;

            foreach (var account in idleAccounts)
            {
                // We will ensure that the account will be processed only once every ReportPullingIntervalByMinutes - 5 (55) minutes
                // If no other processor, the same processor must to process the account in next round
                if (account.LastProcessTime != null && account.LastProcessTime.Value.AddMinutes(Constants.ReportPullingIntervalByMinutes - 5) >= now)
                {
                    continue;
                }

                if (await ReportLeaseTableEntity.TryAcquireLeaseAsync(reportLeaseTable, account.EngagementAccount, processor))
                {
                    return(account.EngagementAccount);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public async Task OnAccountCreatedOrUpdatedAsync(string engagementAccount)
        {
            // Create history table if not exist
            await GetHistoryTableAsync(engagementAccount, true);

            // Init record in report lease table
            await ReportLeaseTableEntity.InitAccountAsync(reportLeaseTable, engagementAccount);
        }
Ejemplo n.º 3
0
 public static async Task DeleteAccountAsync(CloudTable table, string engagementAccount)
 {
     var entity = new ReportLeaseTableEntity(engagementAccount)
     {
         ETag = "*"
     };
     var operation = TableOperation.Delete(entity);
     await table.ExecuteAsync(operation);
 }
Ejemplo n.º 4
0
        public async Task OnAccountDeletedAsync(string engagementAccount)
        {
            // Delete history table
            var historyTable = await GetHistoryTableAsync(engagementAccount);

            await historyTable.DeleteIfExistsAsync();

            // Delete record in report lease table
            await ReportLeaseTableEntity.DeleteAccountAsync(reportLeaseTable, engagementAccount);
        }
Ejemplo n.º 5
0
 public static async Task InitAccountAsync(CloudTable table, string engagementAccount)
 {
     var entity    = new ReportLeaseTableEntity(engagementAccount);
     var operation = TableOperation.InsertOrMerge(entity);
     await table.ExecuteAsync(operation);
 }
Ejemplo n.º 6
0
 public async Task ReleaseAccountForPullingReportAsync(string processor, string engagementAccount)
 {
     await ReportLeaseTableEntity.TryReleaseLeaseAsync(reportLeaseTable, engagementAccount, processor);
 }