Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xpub-epmc
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Literature-services
public-projects
xpub-epmc
Commits
c04897ea
Commit
c04897ea
authored
5 years ago
by
MoSelim
Browse files
Options
Downloads
Patches
Plain Diff
#652
handle xml parsing on write stream finish
parent
21baf02e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!169
Dev
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/ncbi-integration/fromNcbi.js
+32
-11
32 additions, 11 deletions
server/ncbi-integration/fromNcbi.js
with
32 additions
and
11 deletions
server/ncbi-integration/fromNcbi.js
+
32
−
11
View file @
c04897ea
...
...
@@ -12,6 +12,7 @@ const {
}
=
require
(
'
../xpub-model/entities/manuscript/helpers/transform
'
)
const
NCBI_RESPONSE_EXT
=
new
RegExp
(
/
\S
+.ld.response.xml$/i
)
let
c
=
new
Client
()
;(
async
()
=>
{
const
beforeUpdate
=
Date
.
now
()
...
...
@@ -23,11 +24,11 @@ function close(c) {
c
.
end
()
ManuscriptAccess
.
knex
().
destroy
()
c
=
null
logger
.
info
(
'
connection terminated
'
)
process
.
exit
()
}
async
function
fromNcbi
()
{
let
c
=
new
Client
()
c
.
on
(
'
ready
'
,
()
=>
{
c
.
list
(
`/
${
config
.
get
(
'
ncbi-ftp
'
)[
'
receive-folder
'
]}
`
,
...
...
@@ -50,16 +51,22 @@ async function fromNcbi() {
c
.
get
(
remoteFilePath
,
(
err
,
stream
)
=>
{
if
(
err
)
return
const
path
=
`
${
os
.
tmpdir
()}
/
${
file
.
name
}
`
stream
.
pipe
(
fs
.
createWriteStream
(
path
))
processFile
(
path
).
then
(
response
=>
{
updateManuscriptNcbiStatus
(
file
.
name
,
response
).
then
(()
=>
{
c
.
rename
(
remoteFilePath
,
`
${
remoteFilePath
}
.processed`
,
err
=>
{
if
(
err
)
{
logger
.
info
(
err
)
}
if
(
index
===
array
.
length
-
1
)
{
close
(
c
)
}
const
writeStream
=
stream
.
pipe
(
fs
.
createWriteStream
(
path
))
writeStream
.
on
(
'
finish
'
,
()
=>
{
processFile
(
path
).
then
(
response
=>
{
updateManuscriptNcbiStatus
(
file
.
name
,
response
).
then
(()
=>
{
c
.
rename
(
remoteFilePath
,
`
${
remoteFilePath
}
.processed`
,
err
=>
{
if
(
err
)
{
logger
.
info
(
err
)
}
if
(
index
===
array
.
length
-
1
)
{
close
(
c
)
}
},
)
})
})
})
...
...
@@ -72,6 +79,17 @@ async function fromNcbi() {
c
.
connect
({
host
,
user
,
password
})
}
process
.
on
(
'
uncaughtException
'
,
err
=>
{
logger
.
error
(
'
Uncaught Exception thrown:
'
,
err
)
close
(
c
)
})
.
on
(
'
unhandledRejection
'
,
(
reason
,
promise
)
=>
{
logger
.
error
(
'
Unhandled Rejection at Promise:
'
,
promise
)
logger
.
error
(
'
Reason:
'
,
reason
)
close
(
c
)
})
function
processFile
(
path
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fs
.
readFile
(
path
,
'
utf8
'
,
(
err
,
data
)
=>
{
...
...
@@ -96,6 +114,9 @@ async function updateManuscriptNcbiStatus(fileName, response) {
// filename example: ems76395.2019_01_01-08_30_06.ld.response.xml
const
manuscriptId
=
fileName
.
split
(
'
.
'
)[
0
].
toUpperCase
()
const
manuscript
=
await
ManuscriptAccess
.
selectById
(
manuscriptId
)
if
(
!
manuscript
)
{
throw
new
Error
(
'
manuscript not found in db
'
)
}
const
newIds
=
manuscript
[
'
meta,articleIds
'
].
filter
(
id
=>
id
.
pubIdType
!==
'
pmcid
'
,
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment