This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
103 lines (75 loc) · 2.3 KB
/
app.js
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
require('dotenv').config();
const { migrate, onComplete } = require('./execute');
const neo4jClient = require('./cypher');
const mysqlClient = require('./query');
const ftpClient = require('./ftp');
const { setup : clientSetup, connect : clientConnect, files : clientFiles } = require('./mapping/client');
const { setup : sucSetup, connect : sucConnect, files: sucFiles } = require('./mapping/success_story');
const { setup : vendorSetup, connect : vendorConnect, files: vendorFiles } = require('./mapping/vendor');
const { setup : jobSetup, connect : jobConnect } = require('./mapping/job');
const { setup : productSetup, connect : productConnect, files: productFiles } = require('./mapping/product');
const { setup : categorySetup, connect : categoryConnect } = require('./mapping/product_category');
mysqlClient.connect();
ftpClient.connect();
const setupActions = [
clientSetup,
sucSetup,
vendorSetup,
jobSetup,
productSetup,
categorySetup,
];
const connectActions = [
clientConnect,
sucConnect,
vendorConnect,
jobConnect,
productConnect,
categoryConnect,
];
const fileActions = [
sucFiles,
// clientFiles,
// vendorFiles,
// productFiles,
];
const actions = setupActions.concat(connectActions);
const length = actions.length;
function migrateData() {
if (actions.length > 0) {
const percentage = 1 - (actions.length / length);
const round = Math.round(percentage * 100)
console.log(`${round} %`);
const action = actions.shift();
const obs = action();
if (obs.length <= 0) {
setup();
return;
}
const fork = onComplete(obs);
fork.subscribe((res) => {
setup();
});
} else {
console.log(`100 %`)
console.log("completed");
neo4jClient.driver.close();
mysqlClient.connection.end();
}
}
function migrateFiles() {
ftpClient.ready.subscribe((list) => {
console.log(list.length);
file(list);
});
}
function file(list) {
if (fileActions.length > 0 ) {
const action = fileActions.pop();
onComplete(action(list)).subscribe((res) => { console.log("next file"); file(list)});
} else {
console.log("files completed");
}
}
//migrateData();
migrateFiles();