a preface:
The pros and cons of the major dispatch components are not discussed here, and quantz.net is used because it can perform a second-level task.
Only.jobs project by storing jobs in the database, a dedicated job management task is initiated to cycle the scheduling of each job.
The project is divided into Web management system, service run-side and data-supply logic processing layer.
Data Access uses the Sqlsugar 4.1.1.5 version and currently supports MySQL, SQL Server
Use Quantz.net+topshelf to install as a Windows service.
Two project structure:
The following are introduced:
Only.Jobs.Items is the test job project that was created.
Only.jobs is a scheduling service project with integrated topshelf that can be installed as a Windows service.
Only.Jobs.Core is the core layer of the project, providing data operations externally.
Only.Jobs.Web is the management and status monitoring management system for dispatching tasks.
Let's take a look at the overall effect.
To run the ONLY.JOBS.WEB project:
In the task management module, you can stop and enable each job.
Introduction to three-table structure
Backgroundjob for Task Information Store table
Backgroundjoblog performing a trace log table for a task
Four Implementation Introduction
The task management module configures the project where the job is developed and stores it in the Backgroundjob table.
Create the Managerjob class in the Only.jobs project, Job Scheduler task management.
1 [Disallowconcurrentexecution]2 Public classManagerjob:ijob3 {4 Private ReadOnlyILog _logger = Logmanager.getlogger (typeof(Managerjob));5 6 Public voidExecute (ijobexecutioncontext context)7 {8Version Ver =System.Reflection.Assembly.GetExecutingAssembly (). GetName (). Version;9_logger.infoformat ("managerjob Execute begin Ver."+ver.tostring ());Ten Try One { A NewQuartzmanager (). Jobscheduler (context. Scheduler); -_logger.infoformat ("managerjob Executing ..."); - } the Catch(Exception ex) - { -Jobexecutionexception e2 =NewJobexecutionexception (ex); -E2. refireimmediately =true; + } - finally + { A_logger.infoformat ("managerjob Execute End"); at } - } -}
View Code
Jobscheduler Method:
1 /// <summary>2 ///Job Status control3 /// </summary>4 /// <param name= "Scheduler" ></param>5 Public voidJobscheduler (IScheduler Scheduler)6 {7list<backgroundjobinfo> list =NewBackgroundjobservice (). Geallowschedulejobinfolist ();8 if(List! =NULL&& list. Count >0)9 {Ten foreach(Backgroundjobinfo Jobinfoinchlist) One { AJobkey Jobkey =NewJobkey (JobInfo.BackgroundJobId.ToString (), jobInfo.BackgroundJobId.ToString () +"Group"); - if(Scheduler.checkexists (jobkey) = =false) - { the if(Jobinfo.state = =1|| Jobinfo.state = =3) - { - schedulejob (Scheduler, jobinfo); - if(Scheduler.checkexists (jobkey) = =false) + { - NewBackgroundjobservice (). Updatebackgroundjobstate (Jobinfo.backgroundjobid,0); + } A Else at { - NewBackgroundjobservice (). Updatebackgroundjobstate (Jobinfo.backgroundjobid,1); - } - } - Else if(Jobinfo.state = =5) - { in NewBackgroundjobservice (). Updatebackgroundjobstate (Jobinfo.backgroundjobid,0); - } to } + Else - { the if(Jobinfo.state = =5) * { $ scheduler.deletejob (jobkey);Panax Notoginseng NewBackgroundjobservice (). Updatebackgroundjobstate (Jobinfo.backgroundjobid,0); - } the Else if(Jobinfo.state = =3) + { A NewBackgroundjobservice (). Updatebackgroundjobstate (Jobinfo.backgroundjobid,1); the } + } - } $ } $}
View Code
The rest of the simple is not described here.
Next look at the effect of the operation:
Start the Only.jobs project
It's just a tool project, but you can still get the bricks, though.
Code uploaded GitHub
Https://github.com/mamingbo/Only.Jobs Welcome to download the use.
Quantz.net database-based task scheduling management (Only.jobs)