Beispiel #1
0
        /// <summary>
        /// Look for all jobs that match a certian criteria.
        /// </summary>
        protected override void ProcessRecord()
        {
            Func <AtlasJob, bool> nameSelector    = _ => true;
            Func <AtlasJob, bool> versionSelector = _ => true;

            if (!string.IsNullOrWhiteSpace(JobName))
            {
                var matcher = new Regex(JobName.Replace("*", ".*"));
                nameSelector = j => matcher.Match(j.Name).Success;
            }

            if (!string.IsNullOrWhiteSpace(JobVersion))
            {
                int version = 0;
                if (!int.TryParse(JobVersion, out version))
                {
                    throw new ArgumentException(string.Format("JobVersion must be a valid integer, not '{0}'", JobVersion));
                }

                versionSelector = j => j.Version == version;
            }

            // Now we can actually go through and get all the jobs.

            var jobs = JobParser.FindJobs(j => nameSelector(j) && versionSelector(j));

            // And return what we found out.
            foreach (var j in jobs.Select(fullSpec => new AtlasJobSpec()
            {
                JobName = fullSpec.Name, JobVersion = fullSpec.Version
            }))
            {
                WriteObject(j);
            }
        }
Beispiel #2
0
        public void LoggerJob()
        {
            string sql    = "";
            DbHelp dbHelp = new DbHelp(ConnString);

            #region 更新任务时间
            sql = string.Format("UPDATE [dbo].[sys_job] SET lastFireTime = '{0}', nextFireTime = '{1}' WHERE jobName = '{2}';", LastFireTime, NextFireTime, JobName);
            dbHelp.DataOperator(sql);
            #endregion

            #region 记录任务日志
            stopwatch.Stop();
            JobMessage = "总共耗时:" + stopwatch.Elapsed.TotalMilliseconds.ToString() + " 毫秒";

            JobName       = JobName.Replace("'", "''");
            JobGroup      = JobGroup.Replace("'", "''");
            MethodName    = MethodName.Replace("'", "''");
            MethodParams  = MethodParams.Replace("'", "''");
            JobMessage    = JobMessage.Replace("'", "''");
            ExceptionInfo = ExceptionInfo.Replace("'", "''");

            sql = string.Format(@"INSERT INTO [dbo].[sys_job_log]
                        ([jobName]
                        ,[jobGroup]
                        ,[methodName]
                        ,[methodParams]
                        ,[jobMessage]
                        ,[exceptionInfo]
                        ,[createTime]
                        ,[createBy])
                    VALUES
                        ('{0}'
                        ,'{1}'
                        ,'{2}'
                        ,'{3}'
                        ,'{4}'
                        ,'{5}'
                        , GETDATE()
                        , 'System')", JobName, JobGroup, MethodName, MethodParams, JobMessage, ExceptionInfo);
            dbHelp.DataOperator(sql);
            #endregion
        }