最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

应用程序运行时间少于24小时,并且始终会引发错误

运维笔记admin10浏览0评论

应用程序运行时间少于24小时,并且始终会引发错误

应用程序运行时间少于24小时,并且始终会引发错误

这是每20分钟从Shopify到Google表格展示最新250个订单的应用程序。(ubuntu,Node JS,数字海洋)

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,
    ['',
    '.metadata.readonly']
);
const shopify = new Shopify({
  shopName: 'shopname.myshopify',
  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 = `/${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();
回答如下:

在try / catch中包装后,它不会中断。

发布评论

评论列表(0)

  1. 暂无评论