Example #1
0
        public async Task IsPopulated()
        {
            var buildId = new BuildId(42, JobId.ParseName(Guid.NewGuid().ToString()));

            Assert.False(await _populator.IsPopulated(buildId));

            var key    = BuildResultEntity.GetExactEntityKey(buildId);
            var entity = new DynamicTableEntity()
            {
                PartitionKey = key.PartitionKey,
                RowKey       = key.RowKey
            };
            await _buildResultExactTable.ExecuteAsync(TableOperation.Insert(entity));

            Assert.True(await _populator.IsPopulated(buildId));
        }
Example #2
0
        /// <summary>
        /// Populate the given build and update the unprocessed table accordingly.  If there is no
        /// existing entity in the unprocessed table, this won't add one.  It will only update existing
        /// ones.
        /// </summary>
        internal async Task Populate(BuildId buildId, BuildTablePopulator populator, bool force, CancellationToken cancellationToken)
        {
            var key = UnprocessedBuildEntity.GetEntityKey(buildId);

            try
            {
                // If we are not forcing the update then check for the existence of a completed run before
                // requerying Jenkins.
                if (force || !(await populator.IsPopulated(buildId)))
                {
                    await populator.PopulateBuild(buildId);
                }

                await AzureUtil.MaybeDeleteAsync(_unprocessedBuildTable, key, cancellationToken);
            }
            catch (Exception e)
            {
                // Update the error state for the row.
                var entity = await AzureUtil.QueryAsync <UnprocessedBuildEntity>(_unprocessedBuildTable, key, cancellationToken);

                if (entity != null)
                {
                    entity.StatusText = $"{e.Message} - {e.StackTrace.Take(1000)}";
                    var operation = TableOperation.Replace(entity);
                    try
                    {
                        await _unprocessedBuildTable.ExecuteAsync(operation);
                    }
                    catch
                    {
                        // It's possible the enity was deleted / updated in parallel.  That's okay.  This table
                        // is meant as an approximation of the build state and always moving towards complete.
                    }
                }
            }
        }