예제 #1
0
        private int CheckJobStatus()
        {
            //0 - Unhandled / Error
            //1 - Success
            //2 - Processing

            var hf      = new HangfireRecordEntities();
            var currJob = hf.Jobs.ToList().LastOrDefault();

            var status = currJob?.StateName?.ToLower().Trim();

            if (status != null)
            {
                if (status == "succeeded")
                {
                    return(1);
                }
                else if (status == "processing")
                {
                    return(2);
                }
            }

            return(0);
        }
예제 #2
0
        public ActionResult Progress()
        {
            HangfireRecordEntities hf = new HangfireRecordEntities();

            var operation = hf.Jobs.ToList().OrderBy(x => x.Id).LastOrDefault();

            if (operation.StateName.ToLower() == "succeeded" || operation.StateName.ToLower() == "deleted")
            {
                return(RedirectToAction("Index", "Database"));
            }
            return(View());
        }
예제 #3
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            try
            {
                HangfireRecordEntities hf = new HangfireRecordEntities();

                string url       = HttpContext.Current.Request.ApplicationPath.ToLower();
                var    operation = hf.Jobs.ToList().OrderBy(x => x.Id).LastOrDefault();

                if (operation != null)
                {
                    if (operation.StateName.ToLower() != "succeeded" && operation.StateName.ToLower() != "deleted")
                    {
                        if (HttpContext.Current.User.IsInRole("Admin"))
                        {
                            if (url.ToLower() != "hangfire")
                            {
                                filterContext.Result = new ViewResult
                                {
                                    ViewName = "~/Views/Database/Progress.cshtml"
                                };
                            }
                        }

                        else
                        {
                            filterContext.HttpContext.Response.Clear();
                            filterContext.HttpContext.Response.StatusCode        = (int)HttpStatusCode.ServiceUnavailable;
                            filterContext.HttpContext.Response.StatusDescription = "Database Maintenance";
                            filterContext.Result = new ViewResult
                            {
                                ViewName = "~/Views/Shared/Maintenance.cshtml"
                            };
                        }
                    }
                }
            }
            catch
            {
            }

            base.OnActionExecuting(filterContext);
        }
예제 #4
0
        private IEnumerable <IDisposable> GetHangfireServers()
        {
            HangfireRecordEntities db = new HangfireRecordEntities();

            var connection = db.Database.Connection.ConnectionString;

            GlobalConfiguration.Configuration
            .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
            .UseSimpleAssemblyNameTypeSerializer()
            .UseRecommendedSerializerSettings()
            .UseSqlServerStorage(connection, new SqlServerStorageOptions
            {
                CommandBatchMaxTimeout       = TimeSpan.FromMinutes(5),
                SlidingInvisibilityTimeout   = TimeSpan.FromMinutes(5),
                QueuePollInterval            = TimeSpan.Zero,
                UseRecommendedIsolationLevel = true,
                DisableGlobalLocks           = true
            });


            yield return(new BackgroundJobServer());
        }