Reputation: 34790
I am trying to run a migration on my Parse app and currently I am trying to run a small migration script (which should take less than a second at all). However, while I'm trying to run it (and trying to sort out errors), my app became unavailable for a few minutes. When I enter the developer console, here is what I get:
All requests to my app fail for a few minutes, all my app pages return 404, and all commands at the terminal are delayed for seconds, or even about a minute.
Here is the script that I'm trying to execute (with master key from cURL) (sorry for the explicit language in the code, it was just a quick fix for myself):
Parse.Cloud.define("migratePosts", function(request, response){
var query = new Parse.Query("Posts");
query.find({success: function(results){
for (var i = results.length - 1; i >= results.length - 10; i--) {
var post = results[i];
if(!post.get("User")){
var userQuery = new Parse.Query("_User");
userQuery.equalTo("username", post.get("username"));
userQuery.find({
success:function(users){
var usr = users[0];
post.set("User", usr);
post.save(null, {
success: function(e){
console.log("saved " + post.get("User"));
},
error: function(o,e){
console.error("error " + e.code + ": " + e.message);
}
});
},
error:function(o,e){
console.log("fuck! " + e.code);
}
});
}
}
}, error:function(e){
console.log("more fuck! " + e.message);
}
});
});
At initialization in app.js
, I'm calling to use master key (to run the migration):
Parse.initialize("my app key", "my js key");
Parse.Cloud.useMasterKey();
When I comment out useMasterKey
, my app starts working again, but I still (and don't expect to) can't run the migration. What would be happening? I've checked the API rate limit and I've not exceeded it. How can I run my migration which requires master privileges?
Upvotes: 2
Views: 273
Reputation: 16874
As suggested by the Parse.Cloud
prefix on the userMasterKey()
function, it only works in Parse Cloud Code.
You basically use it to let a cloud function run with no restrictions when you need to, hopefully after being sure you trust the caller or that the code is not going to break things.
In your case, you would add that to the Cloud Function you created, though it sounds like you really should create a Cloud Job for this as it might exceed the 15 second limit if it needs to do a lot of work.
Upvotes: 0