Compare View

switch
from
...
to
 
Commits (2)

Changes

Showing 3 changed files Side-by-side Diff

... ... @@ -8,6 +8,8 @@ const matrix = require('../matrix');
8 8 const controlPanel = require('../control-panel');
9 9 const heartbeat = require('../heartbeat');
10 10  
  11 +const taskArchive = require('./task-archive');
  12 +
11 13 if (config.handler_name) {
12 14 process.title = "KOMODO-GW@" + config.handler_name;
13 15 }
... ... @@ -88,7 +90,16 @@ function forwardCoreTaskToPartner(coreMessage) {
88 90  
89 91 task.remote_product = getRemoteProduct(task.product);
90 92  
91   - partner.buy(task);
  93 + taskArchive.get(task, function(res) {
  94 + if (res && partner.advice) {
  95 + partner.advice(task);
  96 + }
  97 + else {
  98 + partner.buy(task);
  99 + }
  100 + });
  101 +
  102 +
92 103 }
93 104  
94 105 function replaceRc(original_rc) {
gateway/task-archive.js
... ... @@ -0,0 +1,65 @@
  1 +"use strict";
  2 +
  3 +const module_name = require('path').basename(__filename);
  4 +
  5 +const redis = require("redis");
  6 +
  7 +const config = require('../config');
  8 +const logger = require('../logger');
  9 +const matrix = require('../matrix');
  10 +
  11 +let redis_client;
  12 +
  13 +function init() {
  14 + if (!config.redis) {
  15 + return;
  16 + }
  17 +
  18 + redis_client = redis.createClient(config.redis);
  19 +}
  20 +
  21 +function keyword(task) {
  22 + return 'geckoo_' + config.handler_name + '_' + task.trx_id;
  23 +}
  24 +
  25 +function put(task) {
  26 + if (!redis_client) {
  27 + return;
  28 + }
  29 +
  30 + const keyword = keyword(task);
  31 +
  32 + redis_client.set(keyword, JSON.stringify(task));
  33 + redis_client.expire(keyword, 3600 * 24 * 15);
  34 +}
  35 +
  36 +function get(task, cb) {
  37 + if (!redis_client) {
  38 + cb(null);
  39 + return;
  40 + }
  41 +
  42 + redis_client.get(keyword(task), function(res) {
  43 + if (!res) {
  44 + cb(null);
  45 + }
  46 + else {
  47 + let resObj;
  48 +
  49 + try {
  50 + resObj = JSON.parse(res);
  51 + }
  52 + catch(e) {
  53 + cb(null);
  54 + return;
  55 + }
  56 +
  57 + cb(resObj);
  58 + }
  59 + });
  60 +}
  61 +
  62 +init();
  63 +
  64 +exports.put = put;
  65 +exports.get = get;
1 1 {
2 2 "name": "komodo-sdk",
3   - "version": "1.14.1",
  3 + "version": "1.14.2",
4 4 "description": "SDK for Komodo",
5 5 "main": "index.js",
6 6 "scripts": {
... ... @@ -27,6 +27,7 @@
27 27 "moment": "^2.19.1",
28 28 "numeral": "^2.0.6",
29 29 "nunjucks": "^3.0.1",
  30 + "redis": "^2.8.0",
30 31 "request": "^2.81.0",
31 32 "simple-git": "^1.80.1",
32 33 "strftime": "^0.10.0",