コード例 #1
0
        public async Task IsAcquired_WhenLeaseWasNotAcquired_ReturnsTrue()
        {
            // arrange
            //
            await Lease.AcquireAsync(Blob, TimeSpan.FromMinutes(1));

            // act
            //
            var lease = await Lease.AcquireAsync(Blob, TimeSpan.FromMinutes(1));

            // assert
            //
            Assert.False(Lease.IsAcquired(lease));
        }
コード例 #2
0
        private async Task ReleaseLeaseAsync(Lease lease)
        {
            if (Lease.IsAcquired(lease))
            {
                try
                {
                    await Lease.ReleaseAsync(m_chaserExclusiveAccessBlobLock, lease);

                    s_logger.Verbose("Chaser lock was successfully released.");
                }
                catch (Exception exception)
                {
                    s_logger.Error(exception, "Releasing chaser lock failed.");
                }
            }
        }
コード例 #3
0
        public void Start()
        {
            s_logger.Information("Starting pending notifications chaser...");

            m_pollingJob.Start(async cancellationToken =>
            {
                var lease  = Lease.NotAcquired;
                var result = false;

                try
                {
                    lease = await Lease.AcquireAsync(
                        m_chaserExclusiveAccessBlobLock,
                        TimeSpan.FromMinutes(Constants.Settings.PENDING_NOTIFICATIONS_CHASER_EXCLUSIVE_ACCESS_LOCK_TIMEOUT_IN_MINUTES));

                    if (Lease.IsAcquired(lease))
                    {
                        s_logger.Verbose("Chaser lock was successfully acquired. Start pending notification processing...");

                        var processNotificationCount = await ProcessPendingNotificationsAsync();

                        s_logger.Information("Chaser republished {NotificationCount} unpublished notifications.", processNotificationCount);

                        result = processNotificationCount != 0;
                    }
                    else
                    {
                        s_logger.Verbose("Chaser lock wasn't acquired.");
                    }
                }
                catch (Exception exception)
                {
                    s_logger.Error(exception, "Notification processing failed.");
                }

                await ReleaseLeaseAsync(lease);

                return(result);
            });

            s_logger.Information("Pending notifications chaser started.");
        }
コード例 #4
0
        public async Task IsAcquired_WhenLeaseWasAcquired_ReturnsTrue()
        {
            var lease = await Lease.AcquireAsync(Blob, TimeSpan.FromMinutes(1));

            Assert.True(Lease.IsAcquired(lease));
        }