public static void ConfigureBackgroundJobs(ISettingManager settingManager)
        {
            var recurringJobManager = new RecurringJobManager();

            recurringJobManager.RemoveIfExists(BackgroundJobNames.Users);
            recurringJobManager.RemoveIfExists(BackgroundJobNames.Veeam);

            ConfigureUsers(recurringJobManager, settingManager);
            ConfigureVeeam(recurringJobManager, settingManager);
        }
        protected void ClearRecurringJob(Guid productId)
        {
            var jobToken = GetHangfireToken(productId);

            RecurringJobManager.RemoveIfExists(jobToken);
            return;
        }
Example #3
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");
        }
        // This method will kill the current recurring job if it exists
        // and return normally so no retry is attempted.
        protected void ClearAndExit(int projectId)
        {
            var jobToken = GetHangfireToken(projectId);

            RecurringJobManager.RemoveIfExists(jobToken);
            return;
        }
Example #5
0
        private void ScheduleJob(JobConfigDetails job)
        {
            //LogManager.Log($"Starting job: {job.Id}");
            if (string.IsNullOrEmpty(job.Cron) || string.IsNullOrEmpty(job.TypeName))
            {
                return;
            }

            try
            {
                var jobManager = new RecurringJobManager();
                jobManager.RemoveIfExists(job.Id);
                var type = Type.GetType(job.TypeName);
                if (type != null && job.Enabled)
                {
                    var jobSchedule = new Job(type, type.GetMethod("Start"));
                    jobManager.AddOrUpdate(job.Id, jobSchedule, job.Cron, TimeZoneInfo.Local);
                    //LogManager.Log($"Job {job.Id} has started");
                }
                else
                {
                    //LogManager.Log($"Job {job.Id} of type {type} is not found or job is disabled");
                }
            }
            catch (Exception ex)
            {
                //LogManager.Log($"Exception has been thrown when starting the job {ex.Message}", LogLevel.Critical);
            }
        }
        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());
            }
        }
Example #7
0
        private void OnStopped()
        {
            var manager = new RecurringJobManager(JobStorage.Current);

            foreach (var item in StaticValue.CONTAINERS)
            {
                manager.RemoveIfExists($"stats_{item.ID}");
            }
            _logger.LogInformation("Sentry stoped");
        }
Example #8
0
 public void StopJobs()
 {
     using (var conn = JobStorage.Current.GetConnection())
     {
         var manager = new RecurringJobManager();
         foreach (var job in conn.GetRecurringJobs())
         {
             manager.RemoveIfExists(job.Id);
             //LogManager.Log($"Job has been stopped: {job.Id}", LogLevel.Information);
         }
     }
 }
Example #9
0
 public void StopJobs()
 {
     Log.Info("Verificando si hay Jobs pendientes.");
     using (var conn = JobStorage.Current.GetConnection())
     {
         var manager = new RecurringJobManager();
         foreach (var job in conn.GetRecurringJobs())
         {
             manager.RemoveIfExists(job.Id);
             Log.InfoFormat("Job has been stopped: {0}", job.Id);
         }
     }
 }
Example #10
0
        public FlowToken Execute(EntityToken entityToken, ActionToken actionToken, FlowControllerServicesContainer flowControllerServicesContainer)
        {
            var token   = (TaskEntityToken)entityToken;
            var manager = new RecurringJobManager(JobStorage.Current);

            manager.RemoveIfExists(token.Id);

            var treeRefresher = new SpecificTreeRefresher(flowControllerServicesContainer);

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

            return(null);
        }
Example #11
0
        public void Delete(string id)
        {
            try
            {
                var manager = new RecurringJobManager();

                manager.RemoveIfExists(string.Format("Publisher-{0}", id));
            }
            catch (Exception e)
            {
                logger.Error(e, "Error while removing the Job");
                throw e;
            }
        }
Example #12
0
        public object Save(HangfireJobForm data)
        {
            RecurringJobManager manager = new RecurringJobManager();
            RecurringJobDto     job     = HangfireJobForm.JobFromId(data.Id);

            manager.RemoveIfExists(data.Id);
            manager.AddOrUpdate(data.Id, job.Job, data.Cron, TimeZoneInfo.Local);
            job = HangfireJobForm.JobFromId(data.Id);
            while (job.NextExecution == null)
            {
                // Wait for the update to be stored in Hangfire's database
                System.Threading.Thread.Sleep(2000);
                job = HangfireJobForm.JobFromId(data.Id);
            }
            return(new
            {
                Success = true,
                Message = "Settings were saved successfully!",
                LastExecuted = HangfireJobForm.GetLocalDateString(job.LastExecution),
                NextExecution = HangfireJobForm.GetLocalDateString(job.NextExecution)
            });
        }
Example #13
0
        public object CleanOrphaned()
        {
            List <RecurringJobDto> recurringJobs = Hangfire.JobStorage.Current.GetConnection().GetRecurringJobs();
            RecurringJobManager    manager       = new RecurringJobManager();
            int i = 0;

            foreach (RecurringJobDto dto in recurringJobs)
            {
                if (dto.Job == null)
                {
                    i++;
                    manager.RemoveIfExists(dto.Id);
                }
            }

            string message = i < 1 ? "No orphaned jobs to clean" : "Cleaned " + i + " orphaned jobs.";

            return(new
            {
                Success = i > 0,
                Message = message
            });
        }