簡體   English   中英

Parse.com的預定工作

[英]Scheduled Job In Parse.com

我想在Parse中運行帶有預定作業的Cloud Code。(sashido.io)

randomMentor函數使用隨機數選擇我的Class的某個對象並保存為Today Class。 當我通過PF.Cloud.callFunctionInBackground從Swift調用此方法時,它工作得很好。

但我無法從Parse Dashboard工作 我在我的儀表板中創建了一個帶有pickTodaysMentor名稱的預定作業,它嘗試使用Parse.cloud.run閉包運行。 但它始終返回: error loading cloud code Parse.Cloud.define is not a function

有我的functions.js;

Parse.Cloud.define('randomMentor', async function (request, response) {
    var Mentor = Parse.Object.extend('Mentor');
    var countQuery = new Parse.Query(Mentor);
    const count = await countQuery.count();
    const query = new Parse.Query('Mentor');
    const randomInt = Math.floor(Math.random() * count);
    query.equalTo('position', randomInt);
    query.limit(1); // limit to at most 10 results
    const results = await query.find();

    const Today = Parse.Object.extend('Today');
    const today = new Today();
    today.set('mentor', results[0]);
    today.save()
        .then((today) => {
            response.success("Today Mentor Created.");
        }, (error) => {
            response.error(error);
        });
    response.success("Today Mentor Created.");
});

Parse.Cloud.job('pickTodaysMentor', (request) => {
    const { params, headers, log, message } = request;
    message("I just started");
    Parse.Cloud.run('randomMentor', {}, {
        success: function (result) {
        },
        error: function (error) {
        }
    });
});

我不是JS Developer,所以找不到任何解決方案。 我挖掘了教程,指南和搜索引擎,但沒有運氣。 我認為錯誤太過通用,無法找到問題。

你怎么看?

您收到的錯誤表示您的Cloud Code功能無效。

它應該在Parse Server 3.0.0及更高版本中看起來像這樣:

Parse.Cloud.define("function", async (request) => {
  return "Hello World";
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM