notice send time & logger
Showing
2 changed files
with
48 additions
and
5 deletions
@@ -6,6 +6,7 @@ | @@ -6,6 +6,7 @@ | ||
6 | const _ = require('lodash'); | 6 | const _ = require('lodash'); |
7 | const moment = require('moment'); | 7 | const moment = require('moment'); |
8 | const mysqlCli = global.yoho.utils.mysqlCli; | 8 | const mysqlCli = global.yoho.utils.mysqlCli; |
9 | +const logger = global.yoho.logger; | ||
9 | const MemoryCache = require('../../../utils/memory-cache'); | 10 | const MemoryCache = require('../../../utils/memory-cache'); |
10 | 11 | ||
11 | const TABLE_ACT_PRIZE_PRODUCT = 'act_prize_product'; | 12 | const TABLE_ACT_PRIZE_PRODUCT = 'act_prize_product'; |
@@ -91,6 +92,33 @@ function handelActivityList(list, nums) { | @@ -91,6 +92,33 @@ function handelActivityList(list, nums) { | ||
91 | return list; | 92 | return list; |
92 | } | 93 | } |
93 | 94 | ||
95 | +// 抽奖码创建统计,并生成日志 | ||
96 | +const prizeCodeCreateCount = { | ||
97 | + succedTime: 0, | ||
98 | + failedTime: 0, | ||
99 | + logTime: 0, | ||
100 | + success() { | ||
101 | + this.succedTime++; | ||
102 | + this.log(); | ||
103 | + }, | ||
104 | + fail() { | ||
105 | + this.failedTime++; | ||
106 | + this.log(); | ||
107 | + }, | ||
108 | + log() { | ||
109 | + let now = new Date().getTime() / 1000; | ||
110 | + | ||
111 | + if (now - this.logTime < 60 * 1000) { | ||
112 | + return; | ||
113 | + } | ||
114 | + | ||
115 | + this.logTime = now; | ||
116 | + | ||
117 | + // 记录抽奖码创建成功失败次数 | ||
118 | + logger.info(`prize_code_create succed: ${this.succedTime}; failed: ${this.failedTime}`); | ||
119 | + } | ||
120 | +}; | ||
121 | + | ||
94 | module.exports = class extends global.yoho.BaseModel { | 122 | module.exports = class extends global.yoho.BaseModel { |
95 | constructor(ctx) { | 123 | constructor(ctx) { |
96 | super(ctx); | 124 | super(ctx); |
@@ -394,11 +422,15 @@ module.exports = class extends global.yoho.BaseModel { | @@ -394,11 +422,15 @@ module.exports = class extends global.yoho.BaseModel { | ||
394 | 422 | ||
395 | if (info && info.length) { | 423 | if (info && info.length) { |
396 | if (isRetry) { | 424 | if (isRetry) { |
425 | + prizeCodeCreateCount.fail(); // 记录生成抽奖码失败 | ||
426 | + | ||
397 | return ''; | 427 | return ''; |
398 | } else { | 428 | } else { |
399 | return this.createPrizeCode(length, true); | 429 | return this.createPrizeCode(length, true); |
400 | } | 430 | } |
401 | } else { | 431 | } else { |
432 | + prizeCodeCreateCount.success(); // 记录生成抽奖码成功 | ||
433 | + | ||
402 | return prizeCode; | 434 | return prizeCode; |
403 | } | 435 | } |
404 | } | 436 | } |
@@ -538,6 +570,10 @@ module.exports = class extends global.yoho.BaseModel { | @@ -538,6 +570,10 @@ module.exports = class extends global.yoho.BaseModel { | ||
538 | }), | 570 | }), |
539 | uidList: [uid] | 571 | uidList: [uid] |
540 | }, info) | 572 | }, info) |
573 | + }).then(result => { | ||
574 | + if (result.code !== 200) { | ||
575 | + logger.info(`zerobuy_join_notice send fail uid: ${uid}`); | ||
576 | + } | ||
541 | }); | 577 | }); |
542 | } | 578 | } |
543 | }; | 579 | }; |
@@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
5 | */ | 5 | */ |
6 | 6 | ||
7 | const mysqlCli = global.yoho.utils.mysqlCli; | 7 | const mysqlCli = global.yoho.utils.mysqlCli; |
8 | +const logger = global.yoho.logger; | ||
8 | const _ = require('lodash'); | 9 | const _ = require('lodash'); |
9 | const moment = require('moment'); | 10 | const moment = require('moment'); |
10 | 11 | ||
@@ -21,6 +22,10 @@ const TABLE_ACT_PRIZE_PRODUCT = 'act_prize_product'; | @@ -21,6 +22,10 @@ const TABLE_ACT_PRIZE_PRODUCT = 'act_prize_product'; | ||
21 | const TABLE_ACT_PRIZE_PRODUCT_CONTENT = 'act_prize_product_content'; | 22 | const TABLE_ACT_PRIZE_PRODUCT_CONTENT = 'act_prize_product_content'; |
22 | const TABLE_ACT_PRIZE_PRODUCT_USER = 'act_prize_product_user'; | 23 | const TABLE_ACT_PRIZE_PRODUCT_USER = 'act_prize_product_user'; |
23 | 24 | ||
25 | +const NOTICE_BATCH_SEND_USER_NUM = 400; // 批量发送模板消息每个请求uid数量 | ||
26 | +const NOTICE_BATCH_SEND_API_NUM = 10; // 批量发送模板消息每个批次请求数量 | ||
27 | +const NOTICE_BATCH_SEND_INTERVAL = 5000; // 批量发送模板消息批次间隔时间(ms) | ||
28 | + | ||
24 | const timeFormat = (time) => { | 29 | const timeFormat = (time) => { |
25 | if (_.isNumber(time)) { | 30 | if (_.isNumber(time)) { |
26 | time = moment.unix(time); | 31 | time = moment.unix(time); |
@@ -765,9 +770,11 @@ class AdminModel extends global.yoho.BaseModel { | @@ -765,9 +770,11 @@ class AdminModel extends global.yoho.BaseModel { | ||
765 | }) | 770 | }) |
766 | }; | 771 | }; |
767 | 772 | ||
768 | - _.forEach(_.chunk(userList, 400), value => { | 773 | + _.forEach(_.chunk(userList, NOTICE_BATCH_SEND_USER_NUM), value => { |
769 | if (value && value.length) { | 774 | if (value && value.length) { |
770 | - msgApi.push(this.get({data: Object.assign({uidList: value}, msgData)})); | 775 | + msgApi.push(this.get({data: Object.assign({uidList: value}, msgData)}).then(result => { |
776 | + logger.info(`zerobuy_winning_notice send ${result.code === 200 ? 'success' : 'fail'} uids: ${value.join(',')}`); | ||
777 | + })); | ||
771 | } | 778 | } |
772 | }); | 779 | }); |
773 | 780 | ||
@@ -785,10 +792,10 @@ class AdminModel extends global.yoho.BaseModel { | @@ -785,10 +792,10 @@ class AdminModel extends global.yoho.BaseModel { | ||
785 | } | 792 | } |
786 | 793 | ||
787 | setTimeout(() => { | 794 | setTimeout(() => { |
788 | - this.batchSend(_.drop(apis, 20)); | ||
789 | - }, 1000); | 795 | + this.batchSend(_.drop(apis, NOTICE_BATCH_SEND_API_NUM)); |
796 | + }, NOTICE_BATCH_SEND_INTERVAL); | ||
790 | 797 | ||
791 | - return Promise.all(_.take(apis, 20)); | 798 | + return Promise.all(_.take(apis, NOTICE_BATCH_SEND_API_NUM)); |
792 | } | 799 | } |
793 | } | 800 | } |
794 | 801 |
-
Please register or login to post a comment