示例#1
0
 public static void ChangeJobHistoryStatus(this ISchedulerOptions options, string batchId, string jobId, string clientIp, string connectionId, JobStatus status)
 {
     using (var conn = options.CreateConnection())
     {
         conn.Execute($"UPDATE scheduler_job_history SET status = @Status, lastmodificationtime={options.GetCurrentDatetimeSql()} WHERE batchid=@BatchId AND jobid=@JobId AND clientip=@ClientIp AND connectionid=@ConnectionId", new
         {
             BatchId      = batchId,
             JobId        = jobId,
             Status       = status,
             ClientIp     = clientIp,
             ConnectionId = connectionId
         });
     }
 }
示例#2
0
 public static void InsertJobHistory(this ISchedulerOptions options, string batchId, string jobId, string clientIp = null, string connectionId = null)
 {
     using (var conn = options.CreateConnection())
     {
         var currentDatetimeSql = options.GetCurrentDatetimeSql();
         conn.Execute($"INSERT INTO scheduler_job_history (batchid, jobid, status,clientip,connectionid,creationtime,lastmodificationtime) values (@BatchId,@JobId,@Status,@ClientIp,@ConnectionId,{currentDatetimeSql},{currentDatetimeSql})",
                      new
         {
             BatchId      = batchId,
             JobId        = jobId,
             Status       = JobStatus.Fire,
             ClientIp     = clientIp,
             ConnectionId = connectionId
         });
     }
 }
        private static void InitSchedulerNetDatabase(ISchedulerOptions schedulerOptions)
        {
            switch (schedulerOptions.StorageType)
            {
            case StorageType.SqlServer:
            {
                using (var conn = schedulerOptions.CreateConnection())
                {
                    conn.Execute(@"
IF NOT EXISTS  (SELECT  * FROM dbo.SysObjects WHERE ID = object_id(N'[scheduler_job]') AND OBJECTPROPERTY(ID, 'IsTable') = 1)
CREATE TABLE scheduler_job (
  id varchar(32) NOT NULL,
  [group] varchar(255) NOT NULL,
  name  varchar(255) NOT NULL,
  cron  varchar(50) NOT NULL,
  content  varchar(500) DEFAULT NULL,
  jobtype varchar(20) NOT NULL,
  url  varchar(500) DEFAULT NULL,
  method  varchar(20) DEFAULT NULL,
  isenable bit,
  status int,
  creationtime DateTime NOT NULL,
  lastmodificationtime DateTime,
  PRIMARY KEY(id)
)");

                    conn.Execute(@"
IF NOT EXISTS  (SELECT  * FROM dbo.SysObjects WHERE ID = object_id(N'[scheduler_job_history]') AND OBJECTPROPERTY(ID, 'IsTable') = 1)
CREATE TABLE scheduler_job_history (
  batchid varchar(32) NOT NULL,
  jobid varchar(32) NOT NULL,
  clientip varchar(20) NOT NULL,
  connectionid varchar(32) NOT NULL,
  status int,
  creationtime DateTime NOT NULL,
  lastmodificationtime DateTime,
  PRIMARY KEY(batchid,jobid,clientip,connectionid)
)");
                }

                break;
            }

            case StorageType.MySql:
            {
                using (var conn = schedulerOptions.CreateConnection())
                {
                    conn.Execute(@"
CREATE TABLE IF NOT EXISTS scheduler_job (
  id varchar(32) NOT NULL,
  `group` varchar(255) NOT NULL,
  name  varchar(255) NOT NULL,
  cron  varchar(50) NOT NULL,
  content  varchar(500) DEFAULT NULL,
  jobtype varchar(20) NOT NULL,
  url  varchar(500) DEFAULT NULL,
  method  varchar(20) DEFAULT NULL,
  isenable tinyint(1),
  creationtime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  lastmodificationtime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY(id)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ");

                    conn.Execute(@"
CREATE TABLE IF NOT EXISTS scheduler_job_history (
  batchid varchar(32) NOT NULL,
  jobid varchar(32) NOT NULL,
  clientip varchar(20) NOT NULL,
  connectionid varchar(32) NOT NULL,
  status int,
  creationtime timestamp NOT NULL,
  lastmodificationtime timestamp,
  PRIMARY KEY(batchid,jobid,clientip,connectionid)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ");
                }
                break;
            }
            }
        }