简体   繁体   中英

Stop Quartz Job on local machine

Friends,

I am running some quartz jobs on my application. Everything is working fine, the only thing that I want to do is not to run jobs when I am using that application on my local machine. It means that jobs should only run on server, and run on local only when I want them to.

I know there can be a solution to add a boolean constant, if that is true than run otherwise jobs will not run, but how and where to do it?

Also if there is some other thing that can be done?

public class JobScheduler
    {
        public static void Start()
        {
            IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();

            scheduler.Start();

            IJobDetail offersRefreshJob = JobBuilder.Create<OffersRefreshJob>().Build();

            ITrigger triggerForOffersRefreshJob = TriggerBuilder.Create().WithDailyTimeIntervalSchedule
              (s =>
                 s.WithIntervalInMinutes(8)
                .OnEveryDay()
                .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0))
              )
            .Build();

        scheduler.ScheduleJob(offersRefreshJob, triggerForOffersRefreshJob);
    }
}

This is the code of Global.asax.cs file. I have used a boolean RUN_JOBS variable, and called start() only if RUN_JOBS is true, but it still is running jobs on my local machine. It is an ASP.net MVC web application.

public class MvcApplication : System.Web.HttpApplication
    {
        public bool RUN_JOBS = true;
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            if (RUN_JOBS)
            {
                JobScheduler.Start();
            }            
        }
    }

Since your code is running locally, I assume it is in Debug mode and when you deploy to your server it is in Release mode.

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);


        #if !DEBUG
            JobScheduler.Start();
        #endif            
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM