Browse Source

支持定时任务

Joey 5 months ago
parent
commit
c21c5f6d52
1 changed files with 18 additions and 8 deletions
  1. 18 8
      modules/task_fundPerformance.dos

+ 18 - 8
modules/task_fundPerformance.dos

@@ -14,23 +14,25 @@ use fundit::bfiMatcher;
  * 
  *   @param entityType <STRING>: 'MF', 'HF'...
  *   @param date <DATETIME>: 净值更新时间
- * 
+ *   
  *   NOTE: 与Java不同的是当月indicator计算每日触发,不必等到Month-end production
+ *   
+ *   Example: calFundPerformanceTask('MF', 2024.10.28);
+ *            calFundPerformanceTask('MI', 2024.10.28);
  */
-def calFundPerformanceTask(entityType, date) {
+def calFundPerformanceTask(entityType, date=1900.01.01) {
+//date=temporalAdd(2024.11.04T20:40:00, -3d);
 
     rt = '';
 
-    very_old_date = 1990.01.01;
-
-    if(find(['HF', 'MF'], entityType) < 0) return null;
+    if(!(entityType IN ['MF', 'HF', 'MI', 'FI'])) return null;
 
     // 取有最新净值变动的基金列表 (1s)
     tb_cal_funds = get_entity_list_by_nav_updatetime(entityType, NULL, date, true);
 
     if(tb_cal_funds.isVoid() || tb_cal_funds.size() == 0 ) return;
 
-
+    // 按照 MySQL 建好各表
     tb_fund_performance = create_entity_performance();
     tb_fund_indicator = create_entity_indicator();
     tb_fund_risk_stats = create_entity_risk_stats();
@@ -48,13 +50,12 @@ def calFundPerformanceTask(entityType, date) {
     do {
 
         funds = tb_cal_funds[i : min(tb_cal_funds.size(), i+batch_size)];
-        //funds = SELECT * FROM tb_cal_funds WHERE entity_id in ('MF00003PXI', 'MF00003PXX')
 
         if(funds.isVoid() || funds.size() == 0) break;
 
         // 200ms
         fund_info = SELECT entity_id, price_date, inception_date, benchmark_id, ini_value 
-                    FROM ej(funds, get_fund_info(funds.entity_id), 'entity_id', 'fund_id');
+                    FROM ej(funds, get_entity_info(entityType, funds.entity_id), 'entity_id');
 
         // 计算月收益 (12s)
         rets = mix_monthly_returns(entityType, fund_info);
@@ -272,3 +273,12 @@ def calFundIndexCorrelation(entityType, date) {
 
     return coe;
 }
+
+// 定时任务:
+scheduleJob('daily_market_index_performance', "Market Index return and indicator calculation", calFundPerformanceTask{'MI', now().temporalAdd(-3d)}, 23:10m, today(), today()+30, 'D');
+scheduleJob('daily_fund_performance', "Mutual fund return and indicator calculation", calFundPerformanceTask{'MF', now().temporalAdd(-3d)}, 00:00m, today(), today()+30, 'D');
+scheduleJob('daily_portfolio_performance', "Portfolio nav, return and indicator calculation", CalPortfolioPerformanceTask{now().temporalAdd(-3d)}, 01:00m, today(), today()+30, 'D');
+// 查询任务运行; getRecentJobs();
+// 查询任务列表:getScheduledJobs('daily_%');
+// 删除任务:deleteScheduledJob('daily_fund_performance');
+