定时云函数配置
{
"name": "timing",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
},
"main": "index.js",
"cloudfunction-config": {
"memorySize": 512,
"timeout": 600,
"runtime": "Nodejs12",
"concurrency": 20,
"triggers": [{
"name": "myTrigger",
"type": "timer",
"config": "0 25 6,17,23 * * * *"
}]
}
}
定时云函数
'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
uniCloud.callFunction({
name: 'projectinitiation',
data: {}
}).then((res) => {
return res
console.log(res);
}).catch((errr) => {
return errr
console.log(errr);
})
};
定时云函数调用的云函数
'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
uniCloud.callFunction({
name: 'mainproject',
data: {
mode: 'listAll',
data: {
projectStatus: 0
}
}
}).then((res) => {
let editId = []
const timestamp = Date.now();
res.result.data.forEach((item) => {
if (item.start_time <= timestamp) {
editId.push(item._id)
}
})
uniCloud.callFunction({
name: 'mainproject',
data: {
mode: 'modifyEachAll',
data: {
id: editId,
data: {
projectStatus: 1
}
}
}
}).then((ress) => {
return ress
// console.log(res)
}).catch((errr) => {
console.log(errr);
return errr;
})
}).catch((errr) => {
return errr
console.log(errr);
})
};
u***@163.com (作者)
好吧,我试试
2024-04-24 11:58