Commit 8cd4a46e6982e0907962185e43c142e4c9bbffc4
1 parent
4710a1f797
Exists in
master
taskArchive
Showing 3 changed files with 78 additions and 1 deletions Side-by-side Diff
gateway/pull.js
... | ... | @@ -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; |