Exemplo n.º 1
0
        public void Execute(CancellationToken cancellationToken)
        {
            _throttler.Throttle(cancellationToken);

            using (var connection = _storage.GetConnection())
                using (connection.AcquireDistributedLock("recurring-jobs:lock", LockTimeout))
                {
                    var recurringJobIds = connection.GetAllItemsFromSet("recurring-jobs");

                    foreach (var recurringJobId in recurringJobIds)
                    {
                        var recurringJob = connection.GetAllEntriesFromHash(
                            String.Format("recurring-job:{0}", recurringJobId));

                        if (recurringJob == null)
                        {
                            continue;
                        }

                        try
                        {
                            TryScheduleJob(connection, recurringJobId, recurringJob);
                        }
                        catch (JobLoadException ex)
                        {
                            Logger.WarnFormat("Recurring job '{0}' can not be scheduled due to job load exception.", ex, recurringJobId);
                        }
                    }

                    _throttler.Delay(cancellationToken);
                }
        }
Exemplo n.º 2
0
        public void Invoke(TaskContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            _throttler.Throttle(context.CancellationToken);

            Task.WhenAll(_func.Invoke(context));

            _throttler.Delay(context.CancellationToken);
        }
Exemplo n.º 3
0
        public void Invoke(TaskContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            _throttler.Throttle(context.CancellationToken);

            var cronJobs = _jobDictionary.Select(p => p.Value).ToArray();

            Task.WhenAll(cronJobs.Select(job => RunAsync(job, context)));

            _throttler.Delay(context.CancellationToken);
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public void Execute(BackgroundProcessContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            _throttler.Throttle(context.CancellationToken);

            UseConnectionDistributedLock(context.Storage, connection =>
            {
                var recurringJobIds = connection.GetAllItemsFromSet("recurring-jobs");

                foreach (var recurringJobId in recurringJobIds)
                {
                    if (context.IsShutdownRequested)
                    {
                        return;
                    }

                    var recurringJob = connection.GetAllEntriesFromHash(
                        $"recurring-job:{recurringJobId}");

                    if (recurringJob == null)
                    {
                        continue;
                    }

                    try
                    {
                        TryScheduleJob(context.Storage, connection, recurringJobId, recurringJob);
                    }
                    catch (JobLoadException ex)
                    {
                        _logger.WarnException(
                            $"Recurring job '{recurringJobId}' can not be scheduled due to job load exception.",
                            ex);
                    }
                }
            });

            // The code above may be completed in less than a second. Default throttler use
            // the second resolution, and without an extra delay, CPU and DB bursts may happen.
            _throttler.Delay(context.CancellationToken);
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public void Execute(BackgroundProcessContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            _throttler.Throttle(context.CancellationToken);

            foreach (var queueName in _queues)
            {
                using (var connection = context.Storage.GetConnection())
                    using (connection.AcquireDistributedLock($"recurring-jobs:lock:{ queueName }", LockTimeout))
                    {
                        ScheduleJobsForQueue(context, queueName, connection);
                    }
            }
        }
        /// <inheritdoc />
        public void Execute(BackgroundProcessContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            _throttler.Throttle(context.CancellationToken);

            using (var connection = context.Storage.GetConnection())
                using (connection.AcquireDistributedLock($"{PluginConstants.JobSet}:lock", LockTimeout))
                {
                    var recurringJobIds = connection.GetAllItemsFromSet(PluginConstants.JobSet);

                    foreach (var recurringJobId in recurringJobIds)
                    {
                        var recurringJob = connection.GetAllEntriesFromHash(
                            $"{PluginConstants.JobType}:{recurringJobId}");

                        if (recurringJob == null)
                        {
                            continue;
                        }

                        try
                        {
                            TryScheduleJob(context.Storage, connection, recurringJobId, recurringJob);
                        }
                        catch (JobLoadException ex)
                        {
                            Logger.WarnException(
                                $"Recurring job '{recurringJobId}' can not be scheduled due to job load exception.",
                                ex);
                        }
                    }
                }

            // The code above may be completed in less than a second. Default throttler use
            // the second resolution, and without an extra delay, CPU and DB bursts may happen.
            _throttler.Delay(context.CancellationToken);
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        public void Execute(BackgroundProcessContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            _throttler.Throttle(context.CancellationToken);

            using (var connection = context.Storage.GetConnection())
                using (connection.AcquireDistributedLock("recurring-jobs:lock", LockTimeout))
                {
                    var recurringJobIds = connection.GetAllItemsFromSet("recurring-jobs");

                    foreach (var recurringJobId in recurringJobIds)
                    {
                        var recurringJob = connection.GetAllEntriesFromHash(
                            String.Format("recurring-job:{0}", recurringJobId));

                        if (recurringJob == null)
                        {
                            continue;
                        }

                        try
                        {
                            TryScheduleJob(context.Storage, connection, recurringJobId, recurringJob);
                        }
                        catch (JobLoadException ex)
                        {
                            Logger.WarnException(
                                String.Format(
                                    "Recurring job '{0}' can not be scheduled due to job load exception.",
                                    recurringJobId),
                                ex);
                        }
                    }

                    _throttler.Delay(context.CancellationToken);
                }
        }