u***@163.com
u***@163.com
  • 发布:2024-04-22 17:38
  • 更新:2024-04-23 11:04
  • 阅读:46

【报Bug】定时触发云函数 触发了 数据库的数据,定时云函数触发之后数据库数据并没有更改

分类:uniCloud

产品分类: uniCloud/App

示例代码:

定时云函数配置

{  
    "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);  
    })  
};

操作步骤:

执行定时任务

预期结果:

定时任务执行之后,数据库数据进行改变

实际结果:

定时任务执行之后,数据库数据并没有发生改变

bug描述:

使用定时云函数 变更数据库数据,并不能变更数据库数据,但是在本地调用这个定时云函数,数据库的数据是可以变更的,日志里面显示定时器触发成功,数据并没有更改

2024-04-22 17:38 负责人:DCloud_uniCloud_VK 分享
已邀请:
DCloud_uniCloud_VK

DCloud_uniCloud_VK

在云端运行时,所有的请求都要加await的,包括数据库请求,都要加await,云端不支持回调的写法,只能用async + await

要回复问题请先登录注册