Javascript 使用解析服务器的后台作业&;Heroku调度程序

Javascript 使用解析服务器的后台作业&;Heroku调度程序,javascript,android,node.js,heroku,parse-platform,Javascript,Android,Node.js,Heroku,Parse Platform,在我的Android应用程序中使用parse server和heroku。想要创建后台工作,就像Parse.com之前提供的那样,但似乎无法使其正常工作。 在parser server示例文件夹中,我添加了一个jobs.js文件,其中包含以下内容: var Parse = require('parse/node'); Parse.initialize('my_app_id'); Parse.serverURL = 'https://random-name.herokuapp.com/parse'

在我的Android应用程序中使用parse server和heroku。想要创建后台工作,就像Parse.com之前提供的那样,但似乎无法使其正常工作。 在parser server示例文件夹中,我添加了一个jobs.js文件,其中包含以下内容:

var Parse = require('parse/node');
Parse.initialize('my_app_id');
Parse.serverURL = 'https://random-name.herokuapp.com/parse';

function saveSomething(){
var obj = new Parse.Object('my_class', 'random');
obj.save(null, {
    success: function(place){
        console.log("Success!!");
    },
    error: function(place, error){
        console.log("Fail: " + error.message);
    }
});
}

function sayHello() {
console.log('Hello');
}

sayHello();
saveSomething();
sayHello()运行正常,但saveSomething()在运行时会收到“error:unauthorized”消息:heroku run node jobs.js。 所以我有两个问题

1.这是使用parse server和heroku创建后台作业的正确方法吗

2.“jobs.js”代码有什么问题/为了完成后台工作任务,通常应该做些不同的事情

(尝试将javascript键添加到Parse.initialize('app-id','javascript key');没有任何运气)

解决方案是在“Parse.serverURL=''行之后添加“Parse.Cloud.useMasterKey()”,并在“Parse.initialize('my_app_id',js key',master key')中添加应用程序主键;以获得正确的授权

var Parse = require('parse/node');
Parse.initialize('app-id', 'js-key','master-key');
Parse.serverURL = 'https://random-name.herokuapp.com/parse/';
Parse.Cloud.useMasterKey();

function saveSomething(){
var MyClass = Parse.Object.extend("MyClass");
var myclass = new MyClass();
myclass.set("columnName", "value");
myclass.save({
    success: function(place){
        console.log("Success!!");
    },
    error: function(place, error){
        console.log("Fail: " + error.message);
    }
});
}

saveSomething();

希望这对某人有所帮助。

您是否成功地使它与heroku scheduler一起工作?My函数与heroku run node jobs.js——app appName一起使用。现在我想和Heroku调度器一起使用它,你能帮我吗?我要在这行“$”上写什么?你只需要在$行上写“node jobs.js”,就像在本地运行一样,因为你基本上只是在另一台机器上运行它。然后你可以设置你的频率,然后它就会工作了。@Slagathor我计划在Heroku上做类似于这个问题的背景任务。设置任务频率的命令是什么?比如说每小时一次?@Geeroz如果您使用Heroku调度程序,您可以在Heroku仪表板中设置时间间隔。只需在仪表板中按Heroku调度程序,然后点击“编辑”,然后在下拉菜单中选择“每小时”。如果有人感兴趣,我写了一篇文章,介绍如何使用
kue
获取后台工作: