From a4f6307ebfb2b07a47c00b3a4f2ef5ee2d4f858e Mon Sep 17 00:00:00 2001 From: be beet <63141491+beetcb@users.noreply.github.com> Date: Sun, 21 Feb 2021 14:37:34 +0800 Subject: [PATCH] fix(tcb): optimize conf load logic --- serverless/cea/index.js | 8 +++++--- src/cookie.js | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/serverless/cea/index.js b/serverless/cea/index.js index b3c658b..da14805 100644 --- a/serverless/cea/index.js +++ b/serverless/cea/index.js @@ -12,9 +12,11 @@ async function signIn(usersWithTask) { return logs } -async function handler() { - // load config from toml or env - await cea.init() +async function handler(event) { + // load config from toml or env only when we testing + if (!(event.Type === 'Timer')) { + await cea.init() + } // Log in and save cookie to cea, using cea.get('cookie') to get them (this function resolve with an users array) const usersWithTask = await cea.handleCookie() // Sign in diff --git a/src/cookie.js b/src/cookie.js index 06298b6..233bebd 100644 --- a/src/cookie.js +++ b/src/cookie.js @@ -3,9 +3,8 @@ const log = require('../interface/colorLog') const login = require('../crawler/casLogIn') const { signApp } = require('../campusphere/app') -// get|store|update cookie synchronizedly, prevent concurrent overlap writes to conf conf.handleCookie = async () => { - // Return users with curTask + // Return: users with curTask const usersWithTask = [] await Promise.all( conf.get('users').map(async i => {