I'm running Parse Server on heroku and my cloud code functions work except when I try to query.
Parse.Cloud.define('debuggingFn', function(request, response) {
var query = new Parse.Query("Speech");
query.equalTo("speechId", "s_1456277936842");
query.find({
success: function(results) {
console.log('SUCCESS', results)
response.success("Success", results);
},
error: function(a, b) {
// ERROR CAUGHT HERE: 'Heroku | No such app'
console.log('ERROR', a, b)
response.error("Error");
}
});
});
Speech is a valid class and that speechId exists. I don't know what I'm missing?
Found the issue. My SERVER_URL config field in heroku had a typo in it. Fixed that and everything seems to work now :)
Related
CURRENTLY
I am trying to get AWS Textract working on a Lambda function and am following documentation on https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Textract.html#analyzeDocument-property
My Lambda code:
"use strict";
const AWS = require("aws-sdk");
exports.handler = async (event) => {
let params = JSON.parse(event.body);
console.log("Parse as document...");
let textract = new AWS.Textract();
let doc = params["doc"];
let config = {
Document: {
Bytes: doc,
}
};
textract.analyzeDocument(config, function (err, data) {
console.log("analyzing..."); //<-- nothing logged to console if no error
if (err) {
console.log(err, err.stack);
}
// an error occurred
else {
console.log("data:" + JSON.stringfy(data)); //<-- nothing logged to console if no error
} // successful response
});
console.log("Finished parsing as document.");
};
ISSUE
I cannot get the data back from Textract. It seems I am unable to get the callback working entirely. What's odd is if there is an error e.g. my configuration is wrong, the error handling of the callback will print the log and "analyzing..." log, but without error, none of the logs in the callback print.
Current Logs:
Parse as document...
Finished parsing as document.
Expected / Desired Logs:
Parse as document...
analyzing...
data:{textract output}
Finished parsing as document.
Please help!
NOTES
I am using a role for that Lambda that allows it to access Textract.
I get the same result whether I include the HumanLoopConfig settings or not.
Solved, apparently I needed to setup a promise:
let data = await textract.analyzeDocument(config).promise()
console.log("data:"+data );
console.log("Finished parsing as document.")
I have some parse cloud code im running on my self hosted server but im running into an issue where queries are not doing anything. I can run commands through terminal and get data back but when I run a query.find.. nothing happens. For Example:
Parse.Cloud.job("getall", function(request, response) {
var itemStatus = Parse.Object.extend('MovieStatus');
var query = new Parse.Query(itemStatus);
query.find({
success: function(results) {
console.log(results.length)
response.success(results.length);
},
error: function(err) {
response.error(err);
},
useMasterKey : true
})
})
Nothing happens. No error no response. I have added console logs to make sure its at least getting called and it is, but for some reason nothing every returns from the server when I do query.find
I have tried all sorts of things to figure out what the issue is but this affects all of my cloud code so it has to be something in there.
You are using an old syntax. Since version 3.0, Parse Server supports async/await style. Try this:
Parse.Cloud.job("getall", async request => {
​const { log, message } = request;
const ItemStatus = Parse.Object.extend('MovieStatus');
const query = new Parse.Query(ItemStatus);
const results = await query.find({ useMasterKey: true });
log(response.length);
message(response.length);
})
Not this is a job and not a cloud code function. You can invoke this job using Parse Dashboard and you should see the message in the job status section.
I have a function in my cloud code, which works, but I'm not sure how to fix a problem related to it.
Original Problem:
Parse.Cloud.define("assignTokenToUser", function(request, response) {
console.log("Inside assignTokenToUser");
var token = Math.random().toString(30).substring(7);
query = new Parse.Query("User"),
email = request.params.email;
query.equalTo("username", email);
query.find({ useMasterKey: true }).then(function(results) {
query.first({
success: function(user) {
// Successfully retrieved the object.
user.set("emailToken", token);
user.save();
console.log("success...");
response.success(token);
},
error: function(error) {
console.log("error 1...");
response.error(error);
}
});
}, function(error) {
console.log("error 2...");
response.error(error);
});
});
This seemed to be a common problem after scanning the internet, and my analysis is that the useMasterKey needs to be passed each time we use the query object. Correspondingly, my log file shows that when trying to save the user, it gives a Code 206 error.
Log file output:
Inside assignTokenToUser
success...
^[[32minfo^[[39m: Ran cloud function assignTokenToUser for user undefined with:
Input: {"email":"maryam.zafar#emumba.com"}
Result: "p66qm34jd80p0j6ne03fe1q7f" functionName=assignTokenToUser, email=maryam.zafar#emumba.com, user=undefined
going to send an email... with result: p66qm34jd80p0j6ne03fe1q7f
fullLink: https://beatthegym.com/emailVerified?username=maryam.zafar#emumba.com&token=p66qm34jd80p0j6ne03fe1q7f
^[[31merror^[[39m: Error generating response. ParseError { code: 206, message: 'Cannot modify user 4m0VZFsKVt.' } code=206, message=Cannot modify user 4m0VZFsKVt.
[object Object]
So I went on to change my code to the following:
Code:
Parse.Cloud.define("assignTokenToUser", function(request, response) {
console.log("Inside assignTokenToUser");
var token = Math.random().toString(30).substring(7);
query = new Parse.Query("User"),
email = request.params.email;
query.equalTo("username", email);
query.find({ useMasterKey: true }).then(function(results) {
console.log("inside query.find...");
query.first(null, { useMasterKey: true }).then(function(user) {
console.log("inside query.first...");
// Successfully retrieved the object.
user.set("emailToken", token);
user.save(null, { useMasterKey: true }).then(function() {
console.log("inside user.save...");
response.success();
}, function(error) {
response.error(error);
});
response.success(token);
},
function(error) {
console.log("error 1...");
response.error(error);
});
}, function(error) {
console.log("error 2...");
response.error(error);
});
});
Log file:
Inside assignTokenToUser
inside query.find...
inside query.first...
^[[32minfo^[[39m: Ran cloud function assignTokenToUser for user undefined with:
Input: {"email":"maryam.zafar#emumba.com"}
Result: "tqc8m9lo2tcsrqn69c3q0e1q7f" functionName=assignTokenToUser, email=maryam.zafar#emumba.com, user=undefined
inside user.save...
^[[32minfo^[[39m: Ran cloud function assignTokenToUser for user undefined with:
Input: {"email":"maryam.zafar#emumba.com"}
Result: undefined functionName=assignTokenToUser, email=maryam.zafar#emumba.com, user=undefined
[object Object]
Now, the log file gives me a user as "undefined", and the call to the function gives me a pending status in the Chrome Network tab in the Inspector tool, until it turns into 502, and then the request is auto generated by the browser again. All other requests get a correct 200 response.
However, the data seems to be saved.. the record against this email address saves the token generated correctly. But the request from the browser fails and the user is "undefined" while in the original log file, I see the correct user Id... everytime it fails, the function automatically runs again (because the browser is generating another request everytime it gets a 502) and since it is actually supposed to send an email, it's running again and again keeps on generating infinate emails...
Thank you in advance..
Understood this finally:
The user will remain undefined until and unlesss I obtain it using the Parse.User.current() method. The data does save into the database because it is a forced update to the record, however until the user is aunthenticated using the current() method, it will remain undefined.
I see this is an old post but I spotted clear error in the code:
query = new Parse.Query("User")
Should be:
query = new Parse.Query(Parse.User)
Or at least:
query = new Parse.Query("_User")
As User is a predefined class in Parse.
It woked while ago, but suddenly stopped. Looks like it has something to do with session migration but I don't know why and how to deal with it.
So I've got simple cloud code sample:
Parse.Cloud.define("hello", function(request, response) {
response.success("Hello world!");
});
It works fine naturally.
And I want to run it from afterSave trigger like this:
Parse.Cloud.afterSave(Parse.User, function(request) {
Parse.Cloud.run('hello', { test: 'test'}, {
success: function(success) {
console.log(' Hello success.');
},
error: function(error) {
console.error(' hello failed.');
console.error("Got an error " + error.code + " : " + error.message);
}
});
});
Everything like parse commanded in docs
But when I save user it produces error:
I2015-08-14T06:33:16.709Z] hello failed.
I2015-08-14T06:33:16.711Z]Got an error 209 : invalid session token
How can it be? Am I doing something wrong?
[EDIT]
putting this at the beginning of afterSave trigger helped:
Parse.Cloud.useMasterKey();
I understand this is kind of root command, omitting all ACL restrictions. Can't see where I crossed such restrictions while running simple Hello World function example.
I'm trying to access a doc using the GET API of ElasticSearch but eventhough the documentation claims to be real time I cannot seem to make it work.
Here's what I tried:
Indexing an event with a custom id:
POST: http://hostname.com:9200/events/purchase/<custom_id>
Immediatedly retrieving the doc using:
GET: http://hostname.com:9200/events/purchase/<custom_id>
The problem is that the document is not found.
UPDATE:
It seems that the problem only occurs if the index is initially empty and that's the first doc to be written. Subsequent requests are indexed and retrieved just fine.
this might not be the best code but I think this shows what you want. If possible switch to the elasticsearch.js client. That is what is used in this sample code.
var elasticsearch = require('elasticsearch');
var config = {host:'localhost:9200'};
var client = new elasticsearch.Client({
host: config.host,
log:'trace'
});
storeEvent({"title":"My Event"}, 1);
function storeEvent(myEvent, id) {
client.create({
"index":"events",
"type":"purchase",
"id":id,
"body":myEvent
}, function(error,response) {
if (error) {
console.log("Error during creating event");
console.log(error);
} else {
console.log("Submitted event");
}
client.get({
"index":"events",
"type":"purchase",
"id":id
}, function (error,response) {
if (error) {
console.log("Error during obtaining event");
console.log(error);
} else {
console.log(response);
}
})
});
}
Which version are you using? 1.2.0 had a bug involving routing: http://www.elasticsearch.org/blog/elasticsearch-1-2-1-released/
If you fixed things by reindexing your data it's worth noting that it won't be compatible with future versions.