Introduced
In the actual project use in Quartz.net, want to have a management interface can dynamically add job, and avoid to publish every time.
Also saw the garden classmate asked. Here is the introduction of the implementation of dynamic add job several ways, but also two times the core module development.
Directory
One: the traditional way
Two: Frame reflection mode
Three: Process mode
Four: URL mode
V: How the framework is configured
VI: summary
One: the traditional way
1: Inherit Ijob, implement business logic, add to scheduler.
Public classMonitorjob:ijob { Public voidExecute (Ijobexecutioncontext context) {//Do somethingConsole.WriteLine ("Test"); } } //var job = jobbuilder.create<monitorjob> ()// . Withidentity ("Test", "value")// . Build (); //var trigger = (Icrontrigger) triggerbuilder.create ()// . Withidentity ("Test", "value")// . Withcronschedule ("0 0/5 * * *?") // . Build (); //Scheduler. Schedulejob (Job, trigger);
You can also suspend cancellation using Crystalquartz remote management. Before the blog Crystalquartz Remote Management (ii).
Two: Frame reflection mode
This approach requires defining a set of interface frameworks. Like what:
Interface Icustomjob { void excute (string context); void Failed (string error); void Complete (string msg);
1: When we write job the same implementation of this framework interface, class library form.
2: After writing, compile into DLL, upload to our job execution node.
3: In the execution node, get the DLL's job information by reflection.
4: Then build quartz job, add to scheduler.
This is similar to the disadvantage of: the coupling is too high, the development of a large amount. Advantages: Centralized management.
System structure
Three: Process mode
This approach is similar to the Windows Task Scheduler.
1: The user writes its own job without implementing any interfaces and executing the application form.
2: Sends the program to the execution node, which is invoked by the execution node to invoke the job program.
Perform a node call, as shown in the following example:
Public classConsolejob:ijob { Public voidExecute (Ijobexecutioncontext context) {Jobdatamap DataMap=context. Jobdetail.jobdatamap; stringContent = Datamap.getstring ("Jobdata"); varJD =NewJavaScriptSerializer (). Deserialize<consolejobdata>(content); Process P=NewProcess (); P.startinfo.useshellexecute=true; p.StartInfo.FileName=JD. Path; P.startinfo.arguments= JD. Parameters;//Space SplitP.startinfo.windowstyle =processwindowstyle.minimized; P.start (); } }
This approach is relatively: the coupling is moderate, the execution node and job do not care about each other, there is no dependency, the development amount is small.
System structure
Four: URL mode
The URL method is similar to the third one, but the call is not the execution program, but the URL.
1: The consumer implements the business logic in the Web page or service.
2: The URL is then handed to the execution node post or get execution.
Perform a node call, as shown in the following example:
Public classHttpjob:ijob { Public voidExecute (Ijobexecutioncontext context) {varDataMap =context. Jobdetail.jobdatamap; varContent = Datamap.getstring ("Jobdata"); varJD =NewJavaScriptSerializer (). Deserialize(content); if(JD. Parameters = =NULL) JD. Parameters=string. Empty; if(JD. Timeout = =0) JD. Timeout=5* -; varresult =Requesthelper.post (JD. URL, JD. ContentType, JD. Timeout, JD. Parameters, jd.heads); } }
This way the coupling is relatively low, the user does not need to write the application separately, just as the usual business development. Executive Node Authority: just as a trigger.
There are 2 points to note:
1: When requesting a URL, note that both parties have agreed token encryption to prevent non-execution nodes from executing the call.
2: The consumer, if there is a time-consuming operation, it is recommended to execute asynchronously.
System structure
V: How the framework is configured
1: The user uses the Quartz.net framework directly to implement its own job. Pull the execution node configuration from the management side and then manage the execution node yourself.
2: The user can also expose the port to the management party for monitoring and configuration modification.
This form has the least coupling. is to treat the management as a configuration center. PS: Almost the same as the traditional way +crystalquartz.
VI: summary
Through the context. Jobdetail.jobdatamap, we can save the information needed for the job.
Put forward several programs, for the needs of students reference. For your help, please recommend the next n (* ≧▽≦ *) n.
Mr. Mushroom Source: http://www.cnblogs.com/mushroom/p/4231834.html
Quartz.net dynamic Add job Design-(v)