• Quartz_TimeJob例子(C#)


    执行入口:

    using System;
    using System.Collections.Generic;
    using log4net;
    using Quartz;
    using ypt_base.Common.Model;
    using ypt_base.Common.Util.AD;
    using ypt_base.Urms.BLL;
    using ypt_base.Urms.Model.Res;
    
    namespace Quartz_TimerJob.TimeDevice
    {
        /// <summary>
        /// 江苏YPT组织机构信息同步任务
        /// </summary>
        [DisallowConcurrentExecution]               //不允许此 Job 并发执行任务(禁止新开线程执行)
        public class SyncAdOrgUnitJob : IJob
        {
            private static readonly ILog Log = LogManager.GetLogger(typeof(SyncAdOrgUnitJob));
    
            public void Execute(IJobExecutionContext context)
            {
                try
                {
                    Log.InfoFormat("从AD域同步组织机构信息开始:{0}", DateTime.Now);
    
                    // 获取AD域组织信息
                    List<ADModel> adList = new AdHelper().SyncOrgUnit();
    
                    // 获取组织维度信息
                    DictionaryManagerBLL dictBll = new DictionaryManagerBLL();
                    IList<UrmsDictionary> dimensionList = dictBll.GetDictionaryItemByType("orgDimension");
    
                    bool flag = false;
                    MetaOrgBLL orgBll = new MetaOrgBLL();
                    if (adList != null && adList.Count > 0)
                    {
                        flag = orgBll.SaveOrgUnitAndOrgUser(adList, dimensionList);
                    }
                    else
                    {
                        Log.WarnFormat("AD域中不存在所要获取的组织机构信息!");
                    }
    
                    Log.InfoFormat(flag ? "从AD域同步组织机构信息成功!" : "从AD域同步组织机构信息失败!");
                }
    
                catch (Exception ex)
                {
                    Log.Error("从AD域同步组织机构信息异常", ex);
                }
            }
        }
    }

    配置文件:

    ?xml version="1.0" encoding="UTF-8"?>
    
    <!-- This file contains job definitions in schema version 2.0 format -->
    
    <job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
    
      <processing-directives>
        <overwrite-existing-data>true</overwrite-existing-data>
      </processing-directives>
    
      <schedule>
        <!--江苏YPT同步组织机构任务配置-->
        <job>
          <name>SyncAdOrgUnitJob</name>
          <group>SyncAdOrgUnitGroup</group>
          <description>SyncAdOrgUnit job for Quartz Server</description>
          <job-type>Quartz_TimerJob.TimeDevice.SyncAdOrgUnitJob, Quartz_TimerJob</job-type>
          <durable>true</durable>
          <recover>false</recover>
        </job>
    
        <trigger>
          <cron>
            <name>SyncAdOrgUnitTrigger</name>
            <group>SyncAdOrgUnitGroup</group>
            <job-name>SyncAdOrgUnitJob</job-name>
            <job-group>SyncAdOrgUnitGroup</job-group>
            <cron-expression>0 23 15 * * ?</cron-expression>
            <!--[秒] [分] [小时] [日] [月] [周] [年]-->
          </cron>
        </trigger>
    
      </schedule>
    </job-scheduling-data>
  • 相关阅读:
    vscode的settings.json最新配置
    RSA和AES混合使用的原理
    自己手动配置脚手架webpack完整详细版(一)
    MySQL下载安装教程完整版
    解决这三个问题的方法:abandon后重提代码、给sourcetree重加工程、ideal上查找历史版本代码、
    synchronized关键字,Lock对象,阻塞队列问题
    volatile关键字
    Python-根据成绩分析是否继续深造
    R语言-美国枪杀案分析
    R语言-ggplot初级
  • 原文地址:https://www.cnblogs.com/tldxh/p/8176256.html
Copyright © 2020-2023  润新知