diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..dde673d --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "ms-azuretools.vscode-azurefunctions" + ] +} \ No newline at end of file diff --git a/europepmcUpload/function.json b/europepmcUpload/function.json new file mode 100644 index 0000000..3bdfa43 --- /dev/null +++ b/europepmcUpload/function.json @@ -0,0 +1,6 @@ +{ + "schedule": "0 0 3 * * *", + "name": "europepmcUpload", + "type": "timerTrigger", + "direction": "in" +} diff --git a/src/index.js b/europepmcUpload/index.js similarity index 83% rename from src/index.js rename to europepmcUpload/index.js index 5474f68..650cecf 100644 --- a/src/index.js +++ b/europepmcUpload/index.js @@ -21,7 +21,7 @@ const getPreprints = async () => { try { const response = await fetch(url); const data = await response.json(); - return data; + return data.data; } catch (error) { console.log('oh dear, looks like we broke the preprints fetch: ', error); } @@ -129,11 +129,25 @@ const uploadToEuropePMC = async () => { client.close(); }; -buildXML() - .then(() => { - if (FTP_USER && FTP_PASS) { - uploadToEuropePMC(); +module.exports = function(context, europepmcUpload) { + if (europepmcUpload && europepmcUpload.IsPastDue && context) { + context.log('Upload is running late!'); + } + buildXML() + .then(() => { + if (FTP_USER && FTP_PASS) { + uploadToEuropePMC(); + } + return; + }) + .catch((err) => console.error('Failed to export:', err)); + if (context) { + if (europepmcUpload && europepmcUpload.IsPastDue) { + context.log('Upload is running late!'); } - return; - }) - .catch((err) => console.error('Failed to export:', err)); + const timestamp = new Date().toISOString(); + context.log('Upload ran!', timestamp); + } +}; + + diff --git a/host.json b/host.json new file mode 100644 index 0000000..05291ed --- /dev/null +++ b/host.json @@ -0,0 +1,15 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + } + } + }, + "extensionBundle": { + "id": "Microsoft.Azure.Functions.ExtensionBundle", + "version": "[1.*, 2.0.0)" + } +} \ No newline at end of file diff --git a/local.settings.json b/local.settings.json new file mode 100644 index 0000000..5240831 --- /dev/null +++ b/local.settings.json @@ -0,0 +1,7 @@ +{ + "IsEncrypted": false, + "Values": { + "FUNCTIONS_WORKER_RUNTIME": "node", + "AzureWebJobsStorage": "" + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index a65ce53..a580460 100644 --- a/package-lock.json +++ b/package-lock.json @@ -152,6 +152,11 @@ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, + "basic-ftp": { + "version": "4.6.6", + "resolved": "https://registry.npmjs.org/basic-ftp/-/basic-ftp-4.6.6.tgz", + "integrity": "sha512-5nTclY5mVxjeFoq9cBTzgQvcM1UfeGTd4hCCvb8AgC88wHMDQCD4UX5hZo2jaiSh96Nf+gFy1joNI9iH639bvQ==" + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", diff --git a/package.json b/package.json index 2b92e3e..fe8b4b5 100644 --- a/package.json +++ b/package.json @@ -21,16 +21,16 @@ "doc": "docs" }, "homepage": "https://github.com/throneless-tech/PREreview-feed", - "main": "./src/index.js", + "main": "./europepmcUpload/index.js", "bin": { - "prereview-feed": "./src/index.js" + "prereview-feed": "./europepmcUpload/index.js" }, "files": [ - "./src/index.js" + "./europepmcUpload/index.js" ], "scripts": { - "start": "npx ./src/index.js", - "lint": "eslint --ignore-path .gitignore --ext js --fix ./src" + "start": "npx ./europepmcUpload/index.js", + "lint": "eslint --ignore-path .gitignore --ext js --fix ./feed" }, "engines": { "node": ">=12.0" @@ -94,6 +94,7 @@ "prettier": "^2.1.0" }, "dependencies": { + "basic-ftp": "^4.6.6", "feed": "^4.2.1", "node-fetch": "^2.6.0", "xmlbuilder2": "^2.3.1"