按周调度任务支持实现


esb代码已在trunk修改,修改3.16.2分支时参照下面代码或者引用trunk中的文件。

hotfox及接口已在trunk修改并复制到3.2.1分支.

esb配置

esb.conf任务调度配置
扩展后的esb支持按周调度任务.
<Schedule Type="3"> <!-- Type=3表示按周调度 -->
<WeekNum>2</WeekNum> <!-- 每N周执行一次.默认1 -->
<WeekDay>0</WeekDay> <!-- 星期几执行 0表示不限定,可以是一周的任何一天.1-7分别表示星期1到星期日-->
<StartTime>21:00</StartTime> <!--执行的时间点.hhmm格式,默认:2:00-->
<Interval>60</Interval> <!--时间检查间隔(默认1分钟) -->
<LastDay>2013-3-15</LastDay> <!--上次执行日期 -->
</Schedule>

esb插件代码修改


esb_task.cpp
修改c_esb_scan_rule_factory::create函数
i_esb_scan_rule* c_esb_scan_rule_factory::create(INode* parentNode)
{
    INode* subNode = parentNode->GetAttributes()->GetChildNodes("Type")->GetChildNode(0);
    if(subNode == NULL)
        return NULL;
    i_esb_scan_rule* c_rule;
    int type = (int)*subNode;
    switch(type) {
        case 1:
            c_rule = new c_esb_scan_rule_date;
            break;
        case 3:
            c_rule = new c_esb_scan_rule_week;        
            break;
        default:
            c_rule = new c_esb_scan_rule_time;

    }
    c_rule->ReadConfig(parentNode);
    return c_rule;
}

在c_esb_scan_rule_date::settaskinfo之后增加:
int c_esb_scan_rule_week::ReadConfig(INode* parentNode) {

    INode* subNode = parentNode->GetChildNodes()->GetChildNodes("WeekNum")->GetChildNode(0);
    if (subNode)
        week_num_ = (int)*subNode;

    subNode = parentNode->GetChildNodes()->GetChildNodes("WeekDay")->GetChildNode(0);
    if (subNode)
        week_day_ = (int)*subNode;

    subNode = parentNode->GetChildNodes()->GetChildNodes("StartTime")->GetChildNode(0);
    if (subNode) {
        vector<string> vs;
        string s = (string)*subNode;
        SplitString(s.c_str(),vs,':');
        start_time_ = atoi(vs[0].c_str())*100+atoi(vs[1].c_str());
    }

    parentNode->GetChildNodes()->GetChildNodes("Interval")->GetChildNode(0);
    if (subNode)
        interval_ = (int)*subNode;

    parentNode->GetChildNodes()->GetChildNodes("LastDay")->GetChildNode(0);
    if(!subNode)
        return -1;
    vector<string> vs;
    string s = (string)*subNode;
    SplitString(s.c_str(),vs,'-');
    last_day_ = atoi(vs[0].c_str())*10000+atoi(vs[1].c_str())*100+atoi(vs[2].c_str());

    return 0;
}

void c_esb_scan_rule_week::settaskinfo(IDeamonTask* task) {
    task->set_week_strategy(week_num_,week_day_,start_time_,interval_,last_day_);
}

esb_task.h
在c_esb_scan_rule_date定义后增加:
class c_esb_scan_rule_week : public i_esb_scan_rule
{
protected:
    unsigned short week_num_;
    unsigned short week_day_;
    unsigned short start_time_; /// 从指定的时间开始(24小时制,hhmm)
    unsigned short interval_; ///< 时间检查间隔(默认1分钟)
    unsigned long last_day_; ///< 最后执行成功的日期(yyyymmdd)
public:
    c_esb_scan_rule_week():week_num_(1),week_day_(0),start_time_(200),interval_(60),last_day_(0) {
    }
    virtual int ReadConfig(INode* parentNode);
    virtual void settaskinfo(IDeamonTask* task);
};

hotfox修改


为支持按周调度,hotfox工程修改以下文件:
DeamonTask.h/DeamonTask.cpp/i_deamon_task_mgr.h

主要是增加以下方法:
struct IDeamonTask {
    ///< 设置按周调度策略
    virtual int set_week_strategy(unsigned short week_num,unsigned short week_day,unsigned short start_time,unsigned short interval=60,unsigned long last_day=0) = 0;
    ///< 获取任务ID,此任务ID由调用者指定
    virtual const char* get_id() const = 0;
    ///< 设置任务ID
    virtual void set_id(const char *id) = 0;

    ///< 设置任务成功回调函数,如执行记录最后执行时间
    virtual void set_done_cb(OnTaskDone func) = 0;
    ///< 获取任务回调函数
    virtual OnTaskDone get_done_cb() = 0;
};
  
hotfox.exe从下列位置获取:
\hotfox\branches\RB-3.2.1\bin

接口文件i_deamon_task_mgr.h已更新 branches\RB-3.16.2\源代码\Server\common\hotfox\include.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值