From 8c41b0a2bcaa16894c5fe39ac0ffb9ed92170b24 Mon Sep 17 00:00:00 2001 From: Josh King Date: Thu, 1 Jul 2021 13:49:51 -0400 Subject: [PATCH] Finish azure job fixes. --- EuropepmcUpload/function.json | 10 ++++++++++ {europepmcUpload => EuropepmcUpload}/index.js | 14 +++++++++----- europepmcUpload/function.json | 6 ------ local.settings.json | 8 ++++++-- package.json | 2 +- script.js | 3 +++ 6 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 EuropepmcUpload/function.json rename {europepmcUpload => EuropepmcUpload}/index.js (88%) delete mode 100644 europepmcUpload/function.json create mode 100644 script.js diff --git a/EuropepmcUpload/function.json b/EuropepmcUpload/function.json new file mode 100644 index 0000000..ea8c551 --- /dev/null +++ b/EuropepmcUpload/function.json @@ -0,0 +1,10 @@ +{ + "bindings": [ + { + "schedule": "0 0 3 * * *", + "name": "europepmcUpload", + "type": "timerTrigger", + "direction": "in" + } + ] +} diff --git a/europepmcUpload/index.js b/EuropepmcUpload/index.js similarity index 88% rename from europepmcUpload/index.js rename to EuropepmcUpload/index.js index 650cecf..c644250 100644 --- a/europepmcUpload/index.js +++ b/EuropepmcUpload/index.js @@ -3,12 +3,15 @@ const fs = require('fs'); const { create } = require('xmlbuilder2'); const ftp = require('basic-ftp'); -let FTP_USER, FTP_PASS; +let FTP_USER, FTP_PASS, FTP_HOST, FTP_DIR; let URL = 'http://prereview2-staging.azurewebsites.net'; +const TMPDIR = process.env.TMPDIR || '/tmp' if (process.env.NODE_ENV === 'production') { URL = 'https://prereview.org'; FTP_USER = process.env.FTP_USER; FTP_PASS = process.env.FTP_PASS; + FTP_HOST = process.env.FTP_HOST; + FTP_DIR = process.env.FTP_DIR; } // only fetches preprints with reviews @@ -103,10 +106,10 @@ const buildXML = async () => { const output = xml.end({ prettyPrint: true }); - fs.writeFile('europepmc.xml', output, (error) => { + fs.writeFile(`${TMPDIR}/europepmc.xml`, output, (error) => { if (error) throw error; console.log( - 'An XML file of all reviews in Europe PMC LabsLink format has been saved to europepmc.xml!', + `An XML file of all reviews in Europe PMC LabsLink format has been saved to ${TMPDIR}/europepmc.xml!`, ); }); }; @@ -116,13 +119,14 @@ const uploadToEuropePMC = async () => { client.ftp.verbose = true; try { await client.access({ - host: 'TBD', + host: `${FTP_HOST}`, user: `${FTP_USER}`, password: `${FTP_PASS}`, secure: false, }); console.log(await client.list()); - await client.uploadFrom('europepmc.xml', 'europepmc.xml'); + await client.cd(`${FTP_DIR}`); + await client.uploadFrom(`${TMPDIR}/europepmc.xml`, 'links.xml'); } catch (err) { console.log(err); } diff --git a/europepmcUpload/function.json b/europepmcUpload/function.json deleted file mode 100644 index 3bdfa43..0000000 --- a/europepmcUpload/function.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "schedule": "0 0 3 * * *", - "name": "europepmcUpload", - "type": "timerTrigger", - "direction": "in" -} diff --git a/local.settings.json b/local.settings.json index 5240831..993e8b7 100644 --- a/local.settings.json +++ b/local.settings.json @@ -2,6 +2,10 @@ "IsEncrypted": false, "Values": { "FUNCTIONS_WORKER_RUNTIME": "node", - "AzureWebJobsStorage": "" - } + "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=prereview2volumes;AccountKey=/xtch1AyHtUuWONP/xLEOYh7YfNE1VAZL1pkKY05VnRawtEEVTt3ES5WA9h6Ef8G6rbq0qRTAJ84sa3treLNIg==;EndpointSuffix=core.windows.net", + "FUNCTIONS_EXTENSION_VERSION": "~3", + "APPINSIGHTS_INSTRUMENTATIONKEY": "4a4f083d-ca7c-4996-a1af-0f40689e9dc9", + "APPLICATIONINSIGHTS_CONNECTION_STRING": "InstrumentationKey=4a4f083d-ca7c-4996-a1af-0f40689e9dc9;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/" + }, + "ConnectionStrings": {} } \ No newline at end of file diff --git a/package.json b/package.json index fe8b4b5..6cbc503 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "./europepmcUpload/index.js" ], "scripts": { - "start": "npx ./europepmcUpload/index.js", + "start": "npx ./script.js", "lint": "eslint --ignore-path .gitignore --ext js --fix ./feed" }, "engines": { diff --git a/script.js b/script.js new file mode 100644 index 0000000..bb4f3a1 --- /dev/null +++ b/script.js @@ -0,0 +1,3 @@ +const upload = require('./EuropepmcUpload/index.js'); + +upload()