Beispiel #1
0
        // Protected methods

        protected virtual async Task Notify()
        {
            var        qPayload  = AgentInfo.Id.Value.Replace("'", "''");
            TDbContext?dbContext = null;

            for (;;)
            {
                try {
                    using (await AsyncLock.Lock()) {
                        if (IsDisposed)
                        {
                            return;
                        }
                        dbContext = DbContext ??= CreateDbContext();
                        await dbContext.Database
                        .ExecuteSqlRawAsync($"NOTIFY {Options.ChannelName}, '{qPayload}'")
                        .ConfigureAwait(false);
                    }
                    return;
                }
                catch (Exception e) {
                    Log.LogError(e, "Notification failed - retrying");
                    DbContext = null;
                    dbContext?.DisposeAsync().Ignore(); // Doesn't matter if it fails
                    await Clock.Delay(Options.RetryDelay).ConfigureAwait(false);
                }
            }
        }
Beispiel #2
0
        protected virtual async Task NotifyAsync()
        {
            var        qPayload  = AgentInfo.Id.Value.Replace("'", "''");
            TDbContext?dbContext = null;

            try {
                using (await AsyncLock.LockAsync()) {
                    if (IsDisposed)
                    {
                        throw Errors.AlreadyDisposed();
                    }
                    dbContext = DbContext ??= CreateDbContext();
                    await dbContext.Database
                    .ExecuteSqlRawAsync($"NOTIFY {Options.ChannelName}, '{qPayload}'")
                    .ConfigureAwait(false);
                }
            }
            catch {
                DbContext = null;
                Notify(Options.RetryDelay);         // Retry
                dbContext?.DisposeAsync().Ignore(); // Doesn't matter if it fails
            }
        }