Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xanadu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
SYNERG
xanadu
Commits
74de83a5
Commit
74de83a5
authored
Mar 09, 2020
by
Nilanjan Daw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed and updated file download bug
parent
901024e7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
22 deletions
+43
-22
dispatch_system/dispatch_daemon/index.js
dispatch_system/dispatch_daemon/index.js
+2
-2
dispatch_system/dispatch_daemon/lib.js
dispatch_system/dispatch_daemon/lib.js
+40
-20
dispatch_system/dispatch_daemon/package.json
dispatch_system/dispatch_daemon/package.json
+1
-0
No files found.
dispatch_system/dispatch_daemon/index.js
View file @
74de83a5
...
...
@@ -77,9 +77,9 @@ libSupport.makeTopic(node_id).then(() => {
/**
* download and start grunt
*/
libSupport
.
download
(
constants
.
grunt_host
,
"
grunt
"
).
then
(()
=>
{
libSupport
.
download
(
constants
.
grunt_host
,
"
grunt
"
,
false
).
then
(()
=>
{
logger
.
info
(
"
Downloaded grunt binary from repository
"
)
fs
.
chmod
(
'
grunt
'
,
0o
5
55
,
(
err
)
=>
{
fs
.
chmod
(
'
grunt
'
,
0o
7
55
,
(
err
)
=>
{
logger
.
info
(
"
grunt made executable. Starting grunt
"
)
let
grunt
=
spawn
(
'
./grunt
'
,
[
node_id
])
grunt
.
stdout
.
on
(
'
data
'
,
data
=>
{
...
...
dispatch_system/dispatch_daemon/lib.js
View file @
74de83a5
const
http
=
require
(
'
http
'
);
const
fetch
=
require
(
'
node-fetch
'
);
const
fs
=
require
(
'
fs
'
);
const
process
=
require
(
'
process
'
)
const
{
spawnSync
}
=
require
(
'
child_process
'
);
...
...
@@ -50,28 +50,48 @@ function makeTopic(id) {
})
}
var
download
=
function
(
url
,
dest
,
cb
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
// var download = function (url, dest, check = true, cb) {
// return new Promise((resolve, reject) => {
// console.log(url);
// if (!check || !fs.existsSync(dest)) {
// var file = fs.createWriteStream(dest);
// var request = https.get(url, function (response) {
// response.pipe(file);
// file.on('finish', function () {
// file.close(cb); // close() is async, call cb after close completes.
// resolve();
// });
// }).on('error', function (err) { // Handle errors
// fs.unlink(dest); // Delete the file async. (But we don't check the result)
// logger.error("download failed" + err.message);
// if (cb) cb(err.message);
// reject(err);
// });
// } else {
// resolve();
// }
// })
// };
const
download
=
(
async
(
url
,
path
,
check
=
true
)
=>
{
if
(
!
check
||
!
fs
.
existsSync
(
path
))
{
console
.
log
(
url
);
if
(
!
fs
.
existsSync
(
dest
))
{
var
file
=
fs
.
createWriteStream
(
dest
);
var
request
=
https
.
get
(
url
,
function
(
response
)
{
response
.
pipe
(
file
);
file
.
on
(
'
finish
'
,
function
()
{
file
.
close
(
cb
);
// close() is async, call cb after close completes.
resolve
();
});
}).
on
(
'
error
'
,
function
(
err
)
{
// Handle errors
fs
.
unlink
(
dest
);
// Delete the file async. (But we don't check the result)
if
(
cb
)
cb
(
err
.
message
);
const
res
=
await
fetch
(
url
);
const
fileStream
=
fs
.
createWriteStream
(
path
);
await
new
Promise
((
resolve
,
reject
)
=>
{
res
.
body
.
pipe
(
fileStream
);
res
.
body
.
on
(
"
error
"
,
(
err
)
=>
{
reject
(
err
);
});
}
else
{
resolve
();
}
})
};
fileStream
.
on
(
"
finish
"
,
function
()
{
resolve
();
});
});
}
}
)
;
function
makeid
(
length
)
{
var
result
=
''
;
...
...
dispatch_system/dispatch_daemon/package.json
View file @
74de83a5
...
...
@@ -16,6 +16,7 @@
"kafka-node"
:
"^5.0.0"
,
"morgan"
:
"^1.9.1"
,
"mqtt"
:
"^3.0.0"
,
"node-fetch"
:
"^2.6.0"
,
"redis"
:
"^2.8.0"
,
"request"
:
"^2.88.2"
,
"winston"
:
"^3.2.1"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment