Ad
Application Works Less Than 24 Hours And Alway Throws An Error
This is the app for rendering latest 250 orders every 20 minutes from Shopify to google sheets. (ubuntu, node js, digital ocean)
const {google} = require('googleapis');
const keys = require('./keys.json');
const Shopify = require('shopify-api-node');
const client = new google.auth.JWT(
keys.client_email,
null,
keys.private_key,
['https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive.metadata.readonly']
);
const shopify = new Shopify({
shopName: 'shopname.myshopify.com',
apiKey: 'key',
password: 'pas'
});
const sheets = google.sheets({version: 'v4', auth: client});
const drive = google.drive({version: 'v3', auth: client});
let links = [];
async function runDrive(ord, sku){
const resDrive = await drive.files.list({
pageSize: 1,
q: sku,
spaces: 'drive',
});
const files = resDrive.data.files;
let link;
if (files.length) {
link = `https://drive.google.com/file/d/${files[0].id}/view`;
} else {
link = 'No files found.';
}
console.log([ord, sku, link])
links.push([ord, sku, link])
}
async function gsrun(){
links = [];
// Shopify - Get orders list
let orders = await shopify.order.list({ limit: 250 });
for (const ord of orders){
for(const item of ord.line_items){
await runDrive(ord.order_number, item.sku)
}
}
// Sheets - Update cells
const clearRange = {
spreadsheetId: 'spreadsheetId',
range: 'Data!A3:G700'
}
const updateData = {
spreadsheetId: 'spreadsheetId',
range: 'Data!A3',
valueInputOption: 'USER_ENTERED',
resource: { values: links},
};
await sheets.spreadsheets.values.clear(clearRange);
console.log('Sheet cleaned')
await sheets.spreadsheets.values.update(updateData);
console.log('Sheet updated')
setTimeout(()=> {
console.log('repeat');
gsrun();
}, 1200000);
}
gsrun();
It works less than twenty-four hours and alway throws this error:
It's my first application.
How to fix it? Should I run the script somewhere outside?
Thanks in advance.
Ad
Answer
After wrapping in try / catch it works without interrupting.
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad