后台作业使用parse-server& Heroku调度程序 [英] Background job using parse-server & Heroku Scheduler

查看:133
本文介绍了后台作业使用parse-server& Heroku调度程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用程序中使用parse-server和heroku。想要创建后台作业,就像之前由Parse.com提供的那样,但似乎无法使其工作。
在parser-server-example文件夹中,我添加了一个包含以下内容的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);
}
});


函数sayHello(){
console.log('Hello');
}

sayHello();
saveSomething();

sayHello()运行良好,但saveSomething()运行时会得到error: heroku运行节点jobs.js。
所以我有2个问题。


1.是否正确使用parse-server& amp; amp; heroku?



2.jobs.js代码有什么问题/为了完成后台工作任务应该以不同的方式完成?



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

解决方案

解决方案是添加Parse.Cloud.useMasterKey();在Parse.serverURL =' https://random-name.herokuapp.com/parse 这行后面,然后添加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 ,错误){
console.log(Fail:+ error.message);
}
});
}

saveSomething();

希望这可以帮助别人。


Using parse-server and heroku for my Android application. Want to create background jobs, like the ones offered by Parse.com earlier, but can't seem to make it work. In the parser-server-example folder, I have added a jobs.js file containing this:

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() runs fine, but saveSomething() get "error: unauthorized" message when i run: heroku run node jobs.js . So I have 2 questions.

1.Is this det correct way to create a background job using parse-server & heroku?

2.Anything wrong with the "jobs.js" code/something that should be done differently in general to accomplish the background job task?

(Tried adding javascript-key to the Parse.initialize('app-id', 'javascript-key'); without any luck)

解决方案

The solutions was to add "Parse.Cloud.useMasterKey();" after the line "Parse.serverURL = 'https://random-name.herokuapp.com/parse', and add the apps master key in the "Parse.initialize('my_app_id', 'js-key', 'master-key'); to get the correct authorisation.

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();

Hope this helps someone.

这篇关于后台作业使用parse-server& Heroku调度程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆