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
         });
     }
 }
 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
         });
     }
 }
        public static string GetCurrentDatetimeSql(this ISchedulerOptions options)
        {
            switch (options.HangfireStorageType.ToLower())
            {
            case "sqlserver":
            {
                return("GETDATE()");
            }

            case "mysql":
            {
                return("CURRENT_TIMESTAMP()");
            }

            default:
            {
                return(null);
            }
            }
        }
        public static string GetGroupSql(this ISchedulerOptions options)
        {
            switch (options.StorageType)
            {
            case StorageType.SqlServer:
            {
                return("[group]");
            }

            case StorageType.MySql:
            {
                return("`group`");
            }

            default:
            {
                throw new NotImplementedException($"{options.StorageType}");
            }
            }
        }
        public static IDbConnection CreateConnection(this ISchedulerOptions options)
        {
            switch (options.StorageType)
            {
            case StorageType.SqlServer:
            {
                return(new SqlConnection(options.ConnectionString));
            }

            case StorageType.MySql:
            {
                return(new MySqlConnection(options.ConnectionString));
            }

            default:
            {
                throw new NotImplementedException($"{options.StorageType}");
            }
            }
        }
        public static string GetCurrentDatetimeSql(this ISchedulerOptions options)
        {
            switch (options.StorageType)
            {
            case StorageType.SqlServer:
            {
                return("GETDATE()");
            }

            case StorageType.MySql:
            {
                return("CURRENT_TIMESTAMP()");
            }

            default:
            {
                throw new NotImplementedException($"{options.StorageType}");
            }
            }
        }
        public static IDbConnection CreateConnection(this ISchedulerOptions options)
        {
            switch (options.HangfireStorageType.ToLower())
            {
            case "sqlserver":
            {
                return(new SqlConnection(options.HangfireConnectionString));
            }

            case "mysql":
            {
                return(new MySqlConnection(options.HangfireConnectionString));
            }

            default:
            {
                return(null);
            }
            }
        }
        public static string GetGroupSql(this ISchedulerOptions options)
        {
            switch (options.HangfireStorageType.ToLower())
            {
            case "sqlserver":
            {
                return("[group]");
            }

            case "mysql":
            {
                return("`group`");
            }

            default:
            {
                return(null);
            }
            }
        }
Exemple #9
0
 public ClientHub(ISchedulerOptions options, ILoggerFactory loggerFactory, ISchedulerNetCache cache)
 {
     _options = options;
     _logger  = loggerFactory.CreateLogger <ClientHub>();
     _cache   = cache;
 }
 public ClientHub(ISchedulerOptions options, ILoggerFactory loggerFactory)
 {
     _options = options;
     _logger  = loggerFactory.CreateLogger <ClientHub>();
 }
Exemple #11
0
 public JobController(IJobManager <Job> jobManager, ILoggerFactory loggerFactory, ISchedulerOptions configuration) : base(jobManager, loggerFactory, configuration)
 {
 }
Exemple #12
0
 public HangFireCallbackJobManager(ILoggerFactory loggerFactory, ISchedulerOptions options) : base(loggerFactory, options)
 {
 }
 public CallbackJobExecutor(ILoggerFactory loggerFactory, ISchedulerOptions options) : base(loggerFactory)
 {
     _options = options;
 }
Exemple #14
0
 public JobExecutor(ILoggerFactory loggerFactory, ISchedulerOptions options, IHubContext <ClientHub> hubContext) : base(loggerFactory)
 {
     _hubContext = hubContext;
     _options    = options;
 }
        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;
            }
            }
        }
Exemple #16
0
 protected BaseController(IJobManager <T> jobManager, ILoggerFactory loggerFactory, ISchedulerOptions options)
 {
     _schedulerOptions = options;
     _jobManager       = jobManager;
     Logger            = loggerFactory.CreateLogger(GetType());
 }
        private static void InitDatabase(ISchedulerOptions schedulerOptions)
        {
            switch (schedulerOptions.HangfireStorageType.ToLower())
            {
            case "sqlserver":
            {
                using (var conn = new SqlConnection(schedulerOptions.HangfireConnectionString))
                {
                    try
                    {
                        conn.Execute(@"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)
) ");
                    }
                    catch (Exception e) when(e.Message.Contains("数据库中已存在名为 'scheduler_job' 的对象。") || e.Message.Contains(""))
                    {
                        // IGNORE
                    }
                    try
                    {
                        conn.Execute(@"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)
)");
                    }
                    catch (Exception e) when(e.Message.Contains("数据库中已存在名为 'scheduler_job_history' 的对象。") || e.Message.Contains(""))
                    {
                        // IGNORE
                    }
                }

                break;
            }

            case "mysql":
            {
                using (var conn = new MySqlConnection(schedulerOptions.HangfireConnectionString))
                {
                    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;
            }
            }
        }
Exemple #18
0
 public RedisSchedulerNetCache(ISchedulerOptions options)
 {
     _options     = options;
     _multiplexer = ConnectionMultiplexer.Connect(_options.Cache.ConnectionString);
     _database    = _multiplexer.GetDatabase(0);
 }