Quartz. Net learning notes 4-> batch processing jobs at different times to execute different tasks

Source: Internet
Author: User

/// Log record

Public static class childllylog
{
Static ilog log = logmanager. getlogger (typeof (childllylog ));
Public static void log (string logtitle)
{
Log. Info (logtitle );

}
Public static void error (string logtitle, exception ex)
{
Log. Error (logtitle, ex );

}
}

 

/// Construct a job Template

Public sealed class etsjobinfo
{
/// <Summary>
/// Initialize the constructor. This job template mainly implements Server Ping and telnet based on different IP Ports, and has implemented simulated login.
/// </Summary>
/// <Param name = "jobname"> </param>
/// <Param name = "jobdescription"> </param>
/// <Param name = "jobtrigger"> </param>
/// <Param name = "jobip"> </param>
/// <Param name = "jobtrackingurl"> </param>
/// <Param name = "jobusername"> </param>
/// <Param name = "jobpsd"> </param>
/// <Param name = "jobport"> </param>
/// <Param name = "jobtype"> </param>
Public etsjobinfo (string jobid, string jobname, string jobdescription, string jobtrigger, string jobip, string jobtrackingurl,
String jobusername, string jobpsd, string jobport, string jobtype)
{
This. _ jobid = jobid;
This. _ jobname = jobname;
This. _ jobdescription = jobdescription;
This. _ jobtrigger = jobtrigger;
This. _ jobip = jobip;
This. _ jobtrackingurl = jobtrackingurl;
This. _ jobloginusername = jobusername;
This. _ jobloginpsd = jobpsd;
This. _ jobport = jobport;
This. _ jobtype = jobtype;
}
/// <Summary>
///
/// </Summary>
Public etsjobinfo ()
{

}
Private string _ jobid;
/// <Summary>
/// Job ID
/// </Summary>
Public String jobid
{
Get {return _ jobid ;}
Set {_ jobid = value ;}
}

private string _ jobname;
///


// job name
///
Public String jobname
{
get {return _ jobname ;}
set {_ jobname = value ;}
}

private string _ jobdescription;
///


///
/ // job description
///
Public String jobdescription
{
get {return _ jobdescription ;}
set {_ jobdescription = value ;}
}
private string _ jobtrigger;
///
// The Cron expression is used for the trigger of a job.
//
Public String jobtrigger
{
get {return _ jobtrigger ;}
set {_ jobtrigger = value ;}
}
private string _ jobip;
///
// ip address of the job
//
Public String jobip
{
get {return _ jobip ;}
set {_ jobip = value ;}
}

private string _ jobtrackingurl;
///


// If you log on, save the logon path
///
Public String jobtrackingurl
{
get {return _ jobtrackingurl ;}
set {_ jobtrackingurl = value ;}
}

private string _ jobloginusername;
///


// user name for Logon
//
Public String jobloginusername
{
get {return _ jobloginusername ;}
set {_ jobloginusername = value ;}
}
private string _ jobloginpsd;
///
// logon password
//
Public String jobloginpsd
{
get {return _ jobloginpsd ;}
set {_ jobloginpsd = value ;}
}
private string _ jobport;
///
// Save the port number if telnet is a simulated port.
///
///
Public String jobport
{
get {return _ jobport ;}
set {_ jobport = value ;}
}

Private string _ jobtype;
/// <Summary>
/// Job types include Ping telnet login, which simulates Ping, telnet, and login operations.
/// </Summary>
Public String jobtype
{
Get {return _ jobtype ;}
Set {_ jobtype = value ;}
}
}

 

// Define a job

Public sealed class childllyquartzjob: ijob
{

# Region ijob Member
Public static int I = 0;
Public void execute (ijobexecutioncontext context)
{
Try
{
I ++;

String jobname = context. jobdetail. Key + "---" + context. jobdetail. description;
Jobdatamap map = context. jobdetail. jobdatamap; // The value passed by the job.
Etsjobinfo STS = map ["key"] As etsjobinfo;
Datetime dt = datetime. now;
Childllylog. Log (STS. jobname + "-> time:" + dt. tostring ("G "));
If (STS. jobtype = "login ")
{
// Doing something
}
Else if (STS. jobtype = "Telnet ")
{
// Doing something
}
Else if (STS. jobtype = "ping ")
{
// Doing something
}
}
Catch (exception ex)
{
Childllylog. Error (ex. Message, ex );
}
}
# Endregion
}

 

 

protected void page_load (Object sender, eventargs e)
{< br> List joblist = new list ();
etsjobinfo eji = new etsjobinfo ("1", "woody_test_01", "test jobs", "/15 ****? "," 127.0.0.1 "," http: // 127.0.0.1/1 "," woody_01 "," woody_01 "," 80 "," ping ");
joblist. add (eji);
eji = new etsjobinfo ("2", "woody_test_02", "test jobs", "/15 ****? "," 127.0.0.1 "," http: // 127.0.0.1/2 "," woody_02 "," woody_02 "," 80 "," Port ");
joblist. add (eji);
eji = new etsjobinfo ("3", "woody_test_03", "test jobs", "/15 ****? "," 127.0.0.1 "," http: // 127.0.0.1/3 "," woody_03 "," woody_03 "," 80 "," Telnet ");
joblist. add (eji);
eji = new etsjobinfo ("4", "woody_test_04", "test jobs", "/15 ****? "," 127.0.0.1 "," http: // 127.0.0.1/4 "," woody_04 "," woody_04 "," 80 "," Telnet ");
joblist. add (eji);

// Scheduler
Ischedulerfactory Sf = new stdschedulerfactory ();
Ischeduler sched = SF. getscheduler ();
Foreach (etsjobinfo SJ in joblist)
{
Dictionary <string, etsjobinfo> etsj = new dictionary <string, etsjobinfo> ();
Etsj. Add ("key", SJ );
// Set the parameters passed by the job. The key-value mode is used.
Jobdatamap map = new jobdatamap (etsj );
Ijobdetail job = jobbuilder
. Create <childllyquartzjob> ()
. Withidentity (SJ. jobname, "etsgroup01 ")
. Usingjobdata (MAP) // -- pass a Class Object
//. Usingjobdata ("name", SJ. jobtrackingurl) // pass a single value
//. Usingjobdata ("logtype", SJ. jobtype) // pass a single value
. Requestrecovery () // ask scheduler to re-execute this job if it was in progress when the scheduler went down...
. Build ();
// Set the trigger
Itrigger trigger = triggerbuilder. Create ()

. Withidentity ("Trigger" + SJ. jobname, "etsgroup01") // trigger mode selection cron expression

. Withcronschedule (SJ. jobtrigger)

. Build ();

Sched. schedulejob (job, trigger );
}
 

Sched. Start ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.