Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ipgallery
/
devops
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Registry
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
62bbbccf
authored
Oct 23, 2018
by
Amir Aharon
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
reload when file is changed
parent
0361c765
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
1 deletions
tools/PollingSimulator/app.js
tools/PollingSimulator/package.json
tools/PollingSimulator/yarn.lock
tools/PollingSimulator/app.js
View file @
62bbbccf
...
...
@@ -4,12 +4,14 @@ const url = require('url');
const
fs
=
require
(
'fs'
);
const
request
=
require
(
'request'
);
const
moment
=
require
(
'moment'
);
const
md5
=
require
(
'md5'
);
var
myArgs
=
require
(
'optimist'
).
argv
,
help
=
'node app.js -p port -f file-path/directory [-d delay-between-samples --postUrl http url to post instead of websocket]'
;
var
config
=
{};
var
jsonFilesMap
=
[];
var
filesMD5
=
[];
//const twoDaysAgoMs = 1000 * 3600 * 47;
/**
...
...
@@ -198,3 +200,29 @@ fs.stat(config.file, (err, stats) => {
}
});
let
fsWait
=
false
;
fs
.
watch
(
config
.
file
,
(
event
,
filename
)
=>
{
if
(
filename
)
{
// avoid temp editing files
if
(
filename
.
startsWith
(
"."
))
return
;
// avoid multiple events
if
(
fsWait
)
return
;
fsWait
=
setTimeout
(()
=>
{
fsWait
=
false
;
},
100
);
try
{
const
fileUrl
=
config
.
file
+
'/'
+
filename
;
const
md5Current
=
md5
(
fs
.
readFileSync
(
fileUrl
));
if
(
filesMD5
[
filename
]
&&
filesMD5
[
filename
]
===
md5Current
){
return
;
}
// else file was really changed
console
.
log
(
`
${
filename
}
file Changed`
);
let
filePrefix
=
getFilePrefix
(
filename
);
handleReadFile
(
fileUrl
,
filePrefix
);
}
catch
(
error
)
{
console
.
log
(
error
);
}
}
});
\ No newline at end of file
tools/PollingSimulator/package.json
View file @
62bbbccf
...
...
@@ -17,11 +17,12 @@
"
express
"
:
"^4.16.2"
,
"
fs
"
:
"0.0.1-security"
,
"
http
"
:
"0.0.0"
,
"
md5
"
:
"^2.2.1"
,
"
moment
"
:
"^2.22.2"
,
"
optimist
"
:
"^0.6.1"
,
"
request
"
:
"^2.83.0"
},
"bin"
:
{
"
ws-event-e
mulator"
:
"./app.js"
"
polling-si
mulator"
:
"./app.js"
}
}
tools/PollingSimulator/yarn.lock
0 → 100644
View file @
62bbbccf
This diff is collapsed.
Click to expand it.
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