-
Notifications
You must be signed in to change notification settings - Fork 0
/
warehoused.patch
110 lines (105 loc) · 6.94 KB
/
warehoused.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
diff --git a/lib/index.js b/lib/index.js
index 76530ed..e80a6d5 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -206,7 +206,7 @@ const SESSIONS = new Map();
const CONFIGS = {};
let GENERATION = 0;
-
+let WAREHOUSED = false;
class Goblin {
static buildApplication(appId, config) {
return appBuilder(appId, config);
@@ -266,6 +266,9 @@ class Goblin {
}
static registerQuest(goblinName, questName, quest, options) {
+ if (goblinName === 'warehouse') {
+ WAREHOUSED = true;
+ }
if (!QUESTSMETA[goblinName]) {
QUESTSMETA[goblinName] = {};
}
@@ -1062,9 +1065,19 @@ class Goblin {
if (!this.lastUpsertData) {
this.lastUpsertData = payload.data;
- yield quest.warehouse.upsert(payload);
+ if (WAREHOUSED) {
+ const warehouse = GOBLINS.get('warehouse').get('warehouse');
+ warehouse._do('upsert', payload);
+ } else {
+ yield quest.warehouse.upsert(payload);
+ }
} else if (!this.lastUpsertData.equals(payload.data)) {
- yield quest.warehouse.upsert(payload);
+ if (WAREHOUSED) {
+ const warehouse = GOBLINS.get('warehouse').get('warehouse');
+ warehouse._do('upsert', payload);
+ } else {
+ yield quest.warehouse.upsert(payload);
+ }
this.lastUpsertData = payload.data;
}
}
@@ -1214,8 +1227,12 @@ class Goblin {
* TODO: think about a way to remove properly garbage after a
* crash.
*/
- yield quest.warehouse.upsert(payload);
-
+ if (WAREHOUSED) {
+ const warehouse = GOBLINS.get('warehouse').get('warehouse');
+ warehouse._do('upsert', payload);
+ } else {
+ yield quest.warehouse.upsert(payload);
+ }
if (
this.TTL === 0 &&
this._goblinConfig &&
@@ -1233,7 +1250,6 @@ class Goblin {
}
result = yield QUESTS[this._goblinName][questName](quest, msg);
-
//Create must return the goblin id if not provided
if (questName === 'create' && !result) {
result = this._goblinId;
@@ -1256,7 +1272,6 @@ class Goblin {
`Fatal error ${msg.topic} missing 'parent' parameter`
);
}
-
let toUpsert = this.getState().state;
if (toUpsert.size === 0) {
toUpsert = Shredder.fromJS({id: this._goblinId});
@@ -1325,13 +1340,27 @@ class Goblin {
/* If an error occurs while the goblin is created, then we must
* delete its instance.
*/
- yield quest.warehouse.deleteBranch({
- branch: this._goblinId,
- });
+ if (WAREHOUSED) {
+ const warehouse = GOBLINS.get('warehouse').get('warehouse');
+ warehouse._do('delete-branch', {
+ branch: this._goblinId,
+ });
+ } else {
+ yield quest.warehouse.deleteBranch({
+ branch: this._goblinId,
+ });
+ }
} else if (isCreating === true) {
- yield quest.warehouse.delCreator({
- branch: this._goblinId,
- });
+ if (WAREHOUSED) {
+ const warehouse = GOBLINS.get('warehouse').get('warehouse');
+ warehouse._do('del-creator', {
+ branch: this._goblinId,
+ });
+ } else {
+ yield quest.warehouse.delCreator({
+ branch: this._goblinId,
+ });
+ }
}
if (questName === 'create') {