后台作业使用parse

编程入门 行业动态 更新时间:2024-10-27 20:36:10
本文介绍了后台作业使用parse-server& Heroku调度程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

var Parse = require('parse / node'); Parse.initialize('my_app_id'); Parse.serverURL ='random-name.herokuapp/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 =' random-name.herokuapp/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 ='random-name.herokuapp/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 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 = 'random-name.herokuapp/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 = 'random-name.herokuapp/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 = 'random-name.herokuapp/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

本文发布于:2023-11-27 05:00:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636701.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:作业   后台   parse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!