就这和 hello word 一样简单的代码, 显示内存占用 63.6mb, 到底是我写的问题, 还是什么原因.
看了眼 docker 里跑的其他几个签到服务, 大多在十几 M 左右, 用 chatgpt 把这段代码转下, 同样用 pm2 启动, 也是占用非常少.
const schedule = require('node-schedule')
const axios = require('axios')
const profiles = require('./config')
const getNowTime = () => {
return new Date()['toLocaleDateString']()
}
const request = () => {
profiles.forEach(async item => {
const {url, headers} = item
console.log(`\n\n------${getNowTime()} - ${url}:开始签到------\n`)
const res = await axios({
url,
method: 'post',
headers,
})
if (res && res.data) {
console.log(`------ ${getNowTime()} 签到成功 ------\n`)
console.log(JSON.stringify(res.data))
} else {
console.log(`------ ${getNowTime()} 签到失败 ------\n`)
console.log(res)
}
})
}
const checkin = () => {
schedule.scheduleJob('0 0 7 * * *', () => {
setTimeout(() => {
request()
}, Math.random() * 10 * 60 * 1000)
})
}
console.log(`开始执行任务-${getNowTime()}`)
checkin()