public async Task <IActionResult> Start([FromQuery] Guid sid)
        {
            var model = _db.Schedules.FirstOrDefault(x => x.Id == sid && x.Status == (int)ScheduleStatus.Stop);

            if (model != null)
            {
                await LoadPluginFile(model);

                ScheduleView view = new ScheduleView()
                {
                    Schedule = model
                };
                view.Keepers = (from t in _db.ScheduleKeepers
                                join u in _db.SystemUsers on t.UserId equals u.Id
                                where t.ScheduleId == model.Id && !string.IsNullOrEmpty(u.Email)
                                select new KeyValuePair <string, string>(u.RealName, u.Email)
                                ).ToList();
                view.Children = (from c in _db.ScheduleReferences
                                 join t in _db.Schedules on c.ChildId equals t.Id
                                 where c.ScheduleId == model.Id && c.ChildId != model.Id
                                 select new { t.Id, t.Title }
                                 ).ToDictionary(x => x.Id, x => x.Title);
                bool success = await QuartzManager.StartWithRetry(view, StartedEvent);

                if (success)
                {
                    return(Ok());
                }
            }
            return(BadRequest());
        }
Example #2
0
        static void Main(string[] args)
        {
            if (!onlyOneMutex())
            {
                return;
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (args.Length >= 4)
            {
                applicationInfo = new Applications()
                {
                    Name      = args[0],
                    Path      = args[1],
                    StartArgs = obainExtraArgs(args),
                    Cycle     = args[args.Length - 1]
                };
                MessageBox.Show(applicationInfo.StartArgs);
            }

            if (!File.Exists($@"{applicationInfo.Path}\{applicationInfo.Name}.exe"))
            {
                MessageBox.Show($"程序{applicationInfo.Name}.exe 不存在,守护进程失败!");
                return;
            }

            QuartzManager.AddJob <AutoRestart>("AutoRestart", int.Parse(applicationInfo.Cycle) == 0 ? 10000 : int.Parse(applicationInfo.Cycle));
            Application.Run(new frmProtect());
        }
        public CustomJsonResult Edit(string operater, RopBackgroundJobEdit rop)
        {
            CustomJsonResult result = new CustomJsonResult();

            if (!QuartzManager.ValidExpression(rop.CronExpression))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "无效的Cron表达式"));
            }

            var backgroundJob = CurrentDb.BackgroundJob.Where(m => m.Id == rop.Id).FirstOrDefault();

            if (backgroundJob == null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "数据为空"));
            }

            backgroundJob.CronExpression            = rop.CronExpression;
            backgroundJob.CronExpressionDescription = rop.CronExpressionDescription;
            backgroundJob.Description = rop.Description;
            backgroundJob.Mender      = operater;
            backgroundJob.MendTime    = DateTime.Now;

            CurrentDb.SaveChanges();

            result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "操作成功");

            return(result);
        }
Example #4
0
        public void Start()
        {
            var Job = new QuartzManager();

            Job.Excute <Job1>();

            Job.Start();
        }
Example #5
0
        public async Task <IActionResult> Stop([FromForm] Guid sid)
        {
            bool success = await QuartzManager.Stop(sid);

            if (success)
            {
                return(Ok());
            }
            return(BadRequest());
        }
Example #6
0
        public async Task <IActionResult> Start([FromQuery] Guid sid)
        {
            bool success = await QuartzManager.StartWithRetry(sid);

            if (success)
            {
                return(Ok());
            }
            return(BadRequest());
        }
Example #7
0
        public async Task <IActionResult> RunOnce([FromQuery] Guid sid)
        {
            bool success = await QuartzManager.RunOnce(sid);

            if (success)
            {
                return(Ok());
            }
            return(BadRequest());
        }
        public async Task <IActionResult> Pause([FromBody] Guid sid)
        {
            bool success = await QuartzManager.Pause(sid);

            if (success)
            {
                return(Ok());
            }
            return(BadRequest());
        }
Example #9
0
        static void Main(string[] args)
        {
            var Job = new QuartzManager();

            Job.Excute <MyJob>();
            Job.Excute <Job1>();

            Job.Start();

            Console.ReadKey();
        }
Example #10
0
        public async Task <IActionResult> Init()
        {
            try
            {
                await QuartzManager.InitScheduler();

                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Example #11
0
        public async Task <IActionResult> Shutdown()
        {
            try
            {
                await QuartzManager.Shutdown(false);

                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Example #12
0
        public async Task <IActionResult> Shutdown()
        {
            try
            {
                DelayedTask.DelayPlanManager.Clear();
                await QuartzManager.Shutdown(false);

                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Example #13
0
        public async Task <IActionResult> StartUp()
        {
            try
            {
                DelayedTask.DelayPlanManager.Init();
                await QuartzManager.InitScheduler();

                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
        public CustomJsonResult Add(string operater, RopBackgroundJobAdd rop)
        {
            CustomJsonResult result = new CustomJsonResult();

            var isExists = CurrentDb.BackgroundJob.Where(m => m.AssemblyName == rop.AssemblyName && m.ClassName == rop.ClassName).FirstOrDefault();

            if (isExists != null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, string.Format("程序集:{0},类名:{1},已存在")));
            }

            var type = QuartzManager.GetClassInfo(rop.AssemblyName, rop.ClassName);

            if (type == null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "程序集或类型无效,无法映射"));
            }

            if (!QuartzManager.ValidExpression(rop.CronExpression))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "无效的Cron表达式"));
            }

            var backgroundJob = new BackgroundJob();

            backgroundJob.Id                        = GuidUtil.New();
            backgroundJob.Name                      = rop.Name;
            backgroundJob.AssemblyName              = rop.AssemblyName;
            backgroundJob.ClassName                 = rop.ClassName;
            backgroundJob.CronExpression            = rop.CronExpression;
            backgroundJob.CronExpressionDescription = rop.CronExpressionDescription;
            backgroundJob.Description               = rop.Description;
            backgroundJob.DisplayOrder              = 0;
            backgroundJob.RunCount                  = 0;
            backgroundJob.Status                    = Enumeration.BackgroundJobStatus.Stoped;
            backgroundJob.IsDelete                  = false;
            backgroundJob.Creator                   = operater;
            backgroundJob.CreateTime                = DateTime.Now;


            CurrentDb.BackgroundJob.Add(backgroundJob);
            CurrentDb.SaveChanges();


            result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "操作成功");

            return(result);
        }
Example #15
0
 public async Task Execute(IJobExecutionContext context)
 {
     using (var scope = new ScopeDbContext())
     {
         var _db         = scope.GetDbContext();
         var stoppedList = _db.Schedules.Where(x => x.Status == (int)ScheduleStatus.Stop).Select(x => x.Id).ToList();
         foreach (var sid in stoppedList)
         {
             JobKey jk = new JobKey(sid.ToString().ToLower());
             if (await context.Scheduler.CheckExists(jk))
             {
                 await QuartzManager.Stop(sid);
             }
         }
     }
 }
Example #16
0
        /// <summary>
        /// Starts this instance, delegates to scheduler.
        /// </summary>
        public virtual async void Start()
        {
            try
            {
                scheduler.ListenerManager.AddJobListener(new SchedulerJobListener(), GroupMatcher <JobKey> .AnyGroup());
                await scheduler.Start();

                var quartzManager = new QuartzManager();
                await quartzManager.JobScheduler(scheduler);

                _logger.Info(string.Format("{0} Start", ServiceName));
            }
            catch (Exception ex)
            {
                _logger.Fatal($"Scheduler start failed: {ex.Message}", ex);
                throw;
            }

            _logger.Info("Scheduler started successfully");
        }
 public async Task Execute(IJobExecutionContext context)
 {
     using (var scope = new ScopeDbContext())
     {
         var _db         = scope.GetDbContext();
         var stoppedList = (from s in _db.Schedules
                            join n in _db.ScheduleExecutors on s.Id equals n.ScheduleId
                            where s.Status == (int)ScheduleStatus.Stop && n.WorkerName == ConfigurationCache.NodeSetting.IdentityName
                            select n.ScheduleId
                            ).ToList();
         foreach (var sid in stoppedList)
         {
             JobKey jk = new JobKey(sid.ToString().ToLower());
             if (await context.Scheduler.CheckExists(jk))
             {
                 await QuartzManager.Stop(sid);
             }
         }
     }
 }
Example #18
0
        /// <summary>
        /// 开启守护
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnStartProtect_Click(object sender, EventArgs e)
        {
            int cycleTime = 0;

            if (applicationInfos.Count > 0)
            {
                cycleTime = int.Parse(applicationInfos[0].Cycle);
                foreach (var applicationInfo in applicationInfos)
                {
                    if (!File.Exists($@"{applicationInfo.Path}\{applicationInfo.Name}.exe"))
                    {
                        MessageBox.Show($"程序{applicationInfo.Name}.exe 不存在,开始守护进程失败,请检查配置文件模板!"
                                        , "络町软件");
                        return;
                    }
                }
            }
            QuartzManager.AddJob <AutoRestart>("AutoRestart", cycleTime == 0 ? 10000 : cycleTime);
            btnStartProtect.Enabled = false;
        }
Example #19
0
        public void Execute(IJobExecutionContext context)
        {
            string  curRunId = Guid.NewGuid().ToString();
            Version Ver      = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

            _logger.InfoFormat("ManagerJob[{0}] Execute begin Ver.", Ver.ToString(), curRunId);
            try
            {
                QuartzManager.JobScheduler(context.Scheduler);
                _logger.InfoFormat("ManagerJob[{0}] Executing ...", curRunId);
            }
            catch (Exception ex)
            {
                JobExecutionException e2 = new JobExecutionException(ex);
                e2.RefireImmediately = true;
            }
            finally
            {
                _logger.InfoFormat("ManagerJob[{0}] Execute end ", curRunId);
            }
        }
Example #20
0
        public async Task Execute(IJobExecutionContext context)
        {
            Version Ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

            _logger.InfoFormat("ManagerJob Execute begin Ver." + Ver.ToString());
            try
            {
                var quartzManager = new QuartzManager();
                await quartzManager.JobScheduler(context.Scheduler);

                _logger.InfoFormat("ManagerJob Executing ...");
            }
            catch (Exception ex)
            {
                JobExecutionException e2 = new JobExecutionException(ex);
                e2.RefireImmediately = true;
            }
            finally
            {
                _logger.InfoFormat("ManagerJob Execute end ");
            }
        }
Example #21
0
 public TaskJobController(ILogger <TaskJobController> logger, QuartzRepository yunYingRepository, QuartzManager quartzManager)
 {
     _logger            = logger;
     _yunYingRepository = yunYingRepository;
     _quartzManager     = quartzManager;
 }
Example #22
0
        /// <summary>
        /// 每半小时检测是否有更新
        /// </summary>
        public static void TimingCheckUpdate()
        {
            string timingCheckUpdate = System.Configuration.ConfigurationManager.AppSettings["TimingCheckUpdate"];

            QuartzManager.AddJob <Updater>("TimingCheckUpdate", timingCheckUpdate);
        }
Example #23
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="quartzManager"></param>
 public QuartzService(ILogger <QuartzService> logger, QuartzManager quartzManager)
 {
     _logger        = logger;
     _quartzManager = quartzManager;
 }