public static void InitializeTenants(this IApplicationBuilder app, ITenantService tenantService)
        {
            //var teervice = app.ApplicationServices.GetRequiredService <ITenantService>();
            var tenants = tenantService.GetTenants().Result;

            foreach (var tenant in tenants)
            {
                GlobalConfiguration.Configuration.UseSqlServerStorage(tenant.ConnectionString);
                var sqlStorage = new SqlServerStorage(tenant.ConnectionString);

                //var myapp = app.New();
                app.UseHangfireDashboard($"/dashboard/{tenant.Name}", new DashboardOptions
                {
                    Authorization = new[] { new HangfireAuthFilter() }
                }, sqlStorage);

                var options = new BackgroundJobServerOptions
                {
                    ServerName = string.Format("{0}.{1}", tenant.Name, Guid.NewGuid().ToString()),
                };

                var jobStorage = JobStorage.Current;

                app.UseHangfireServer(options, null, jobStorage);



                //RecurringJob.AddOrUpdate<IHangfireRecurringJobService>(j => j.CheckForAbandonedCart(), Cron.Minutely);
                var recurringJobManager = new RecurringJobManager();
                recurringJobManager.RemoveIfExists(tenant.Id.ToString());
                recurringJobManager.AddOrUpdate <IHangfireRecurringJobService>(tenant.Id.ToString(), j => j.CheckForAbandonedCart(tenant.ConnectionString), Cron.Minutely);
                recurringJobManager.Trigger(tenant.Id.ToString());
            }
        }
Beispiel #2
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            System.Web.Http.GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            HangfireAspNet.Use(GetHangfireServers);


            //BackgroundJob.Enqueue(() => CrawlerJobs.RemoveAll());
            //BackgroundJob.Enqueue(() => CrawlerJobs.GetDiscounts());

            //using (var connection = JobStorage.Current.GetConnection())
            //{

            //    foreach (var recurringJob in StorageConnectionExtensions.GetRecurringJobs(connection))
            //    {
            //        RecurringJob.RemoveIfExists(recurringJob.Id);
            //    }
            //}
            // BackgroundJob.Enqueue(() => CrawlerJobs.AddGame());


            //RecurringJob.AddOrUpdate(() => CrawlerJobs.RemoveAll(), Cron.Daily);
            var manager = new RecurringJobManager();

            manager.RemoveIfExists("500");
            manager.AddOrUpdate("500", () => CrawlerJobs.GetDiscounts(), Cron.Daily);
            manager.Trigger("500");
        }
Beispiel #3
0
        public void JobUpdate(string recurringJobId, Hangfire.Common.Job job, string interval)
        {
            var manager = new RecurringJobManager();

            //manager.RemoveIfExists("my-job-id");
            manager.AddOrUpdate(recurringJobId, job, interval);
            manager.Trigger(recurringJobId);
        }
Beispiel #4
0
        private static void AddRecurringJobs()
        {
            //LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider());
            //RecurringJob.AddOrUpdate("ev-min-recur", () => Console.WriteLine("Recurring Background Methods"), Cron.Minutely);
            var jobManager = new RecurringJobManager(new SqlServerStorage("HangfireConnection"));
            Action <HttpContext> expression = PerformJob;
            var job = new Job(expression.Method, HttpContext.Current);

            jobManager.AddOrUpdate("recurring-job-minute",
                                   job,
                                   Cron.Minutely());
            jobManager.Trigger("recurring-job-minute");
        }
Beispiel #5
0
        public FlowToken Execute(EntityToken entityToken, ActionToken actionToken, FlowControllerServicesContainer flowControllerServicesContainer)
        {
            var token   = (TaskEntityToken)entityToken;
            var manager = new RecurringJobManager(JobStorage.Current);

            manager.Trigger(token.Id);

            var treeRefresher = new SpecificTreeRefresher(flowControllerServicesContainer);

            treeRefresher.PostRefreshMesseges(new FolderEntityToken(TaskType.Recurring));

            return(null);
        }
Beispiel #6
0
        public object ExecuteNow(HangfireJobForm data)
        {
            RecurringJobManager manager = new RecurringJobManager();
            RecurringJobDto     job     = HangfireJobForm.JobFromId(data.Id);

            manager.Trigger(job.Id);
            job = HangfireJobForm.JobFromId(data.Id);

            return(new
            {
                data.Id,
                job.Cron,
                Success = true,
                Message = "Hangfire job is now queued for execution.",
                LastExecuted = HangfireJobForm.GetLocalDateString(job.LastExecution),
                NextExecution = HangfireJobForm.GetLocalDateString(job.NextExecution)
            });
        }