Skip to content

Commit

Permalink
Finish azure job fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jheretic committed Jul 1, 2021
1 parent 37826d7 commit 8c41b0a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
10 changes: 10 additions & 0 deletions EuropepmcUpload/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"bindings": [
{
"schedule": "0 0 3 * * *",
"name": "europepmcUpload",
"type": "timerTrigger",
"direction": "in"
}
]
}
14 changes: 9 additions & 5 deletions europepmcUpload/index.js → EuropepmcUpload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!`,
);
});
};
Expand All @@ -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);
}
Expand Down
6 changes: 0 additions & 6 deletions europepmcUpload/function.json

This file was deleted.

8 changes: 6 additions & 2 deletions local.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 3 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const upload = require('./EuropepmcUpload/index.js');

upload()

0 comments on commit 8c41b0a

Please sign in to comment.