/// <summary>
        /// Uses the hangfire.
        /// </summary>
        /// <param name="app"> The application. </param>
        /// <param name="workerCount"> </param>
        /// <param name="pathMatch"> </param>
        public static void UseHangfire(IApplicationBuilder app, int workerCount = 0, string pathMatch = "/job-hangfire")
        {
            var queuesHangfire = QueueCustom.GetQueues();

            queuesHangfire.AddRange(QueueCustom.GetQueues().Select(x => x.ToUpper()));
            var backgroundServerOptions = new BackgroundJobServerOptions
            {
                Queues = queuesHangfire.Distinct().ToArray()
            };

            if (workerCount > 0)
            {
                backgroundServerOptions.WorkerCount = workerCount;
            }
            app.UseHangfireServer(backgroundServerOptions);

            app.UseHangfireDashboard(pathMatch, new DashboardOptions
            {
                Authorization                  = new[] { new HangfireAuthorizationFilter(UserDashboardHangfire) },
                IgnoreAntiforgeryToken         = true,
                DisplayStorageConnectionString = false,
                DashboardTitle                 = $"Hangfire {BackgroundJobHangfire.Prefix}",
            });
            //Remove All Job
            RecurringJob.AddOrUpdate <BackgroundJobHangfire>(obj => obj.Delete(), Cron.Daily, queue: QueueCustom.Queue0);
        }
コード例 #2
0
        /// <summary>
        /// Called when the current state of the job is being changed to the specified candidate state. This state change could be intercepted and the final state could be changed
        /// through setting the different state in the context in an implementation of this method.
        /// </summary>
        /// <param name="context"> </param>
        public void OnStateElection(ElectStateContext context)
        {
            EnqueuedState EnqueuedState = context.CandidateState as EnqueuedState;

            if (EnqueuedState != null)
            {
                EnqueuedState.Queue = QueueCustom.GetValue(Queue);
            }
            FailedState failedState = context.CandidateState as FailedState;

            if (failedState != null && failedState.Exception != null)
            {
                //todo push error data
            }
        }
コード例 #3
0
        private static void Main()
        {
            var queue = new QueueCustom<string>();

            queue.Enqueue("Message One");
            queue.Enqueue("Message Two");
            queue.Enqueue("Message Three");
            queue.Enqueue("Message Four");
            queue.Enqueue("Message Five");

            while (queue.Count > 0)
            {
                string message = queue.Dequeue();
                Console.WriteLine(message);
            }
        }
コード例 #4
0
 /// <summary>
 /// </summary>
 /// <param name="queue"> </param>
 public QueueAttribute(string queue)
 {
     Queue = QueueCustom.GetValue(queue);
 }