From ab004d9446ec7b43004d757da95f2111fdc48f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Issue=E5=93=A5?= Date: Sun, 28 Jun 2020 08:17:02 +0800 Subject: [PATCH] try catch create_folder --- src/gd.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/gd.js b/src/gd.js index e93441c..11815c7 100644 --- a/src/gd.js +++ b/src/gd.js @@ -545,19 +545,23 @@ async function create_folders ({ source, old_mapping, folders, root, task_id, se console.log('排队等候的目录数量', limit.pendingCount) }, LOG_DELAY) - do { + while (same_levels.length) { await Promise.all(same_levels.map(async v => { - const { name, id, parent } = v - const target = mapping[parent] || root - const new_folder = await limit(() => create_folder(name, target, service_account)) - count++ - mapping[id] = new_folder.id - const mapping_record = id + ' ' + new_folder.id + '\n' - db.prepare('update task set status=?, mapping = mapping || ? where id=?').run('copying', mapping_record, task_id) + try { + const { name, id, parent } = v + const target = mapping[parent] || root + const new_folder = await limit(() => create_folder(name, target, service_account)) + count++ + mapping[id] = new_folder.id + const mapping_record = id + ' ' + new_folder.id + '\n' + db.prepare('update task set status=?, mapping = mapping || ? where id=?').run('copying', mapping_record, task_id) + } catch (e) { + console.error('创建目录出错:', v, e) + } })) folders = folders.filter(v => !mapping[v.id]) same_levels = [].concat(...same_levels.map(v => folders.filter(vv => vv.parent === v.id))) - } while (same_levels.length && (limit.activeCount || limit.pendingCount)) + } clearInterval(loop) return mapping