在完成请求错误之前退出的进程是随机同意的。 起初我得到了结果,但几分钟后,它就抛出了 这是我使用的代码。
/*function name : parkinfo*/
var AWS = require('aws-sdk');
var mysql = require('mysql');
var connection;
exports.connectWkDatabase = function (event, callback) {
var hostName = event['stage-variables']['dbhost'];
var userName = event['stage-variables']['dbusername'];
var dbPassword = event['stage-variables']['dbpassword'];
var databaseName = event['stage-variables']['dbname'];
var dbPort = event['stage-variables']['dbport'];
connection = mysql.createConnection({
host: hostName,
user: userName,
password: dbPassword,
database: databaseName,
port: dbPort,
debug: false
});
connection.connect(function (err) {
if (err) console.log(err);
else {
console.log('db connected');
};
});
callback({ 'status': 'OK' });
};
exports.getParkinfo = function (event, callback) {
if (event['params']['querystring']['keepersScheduleId'])
{
var sql = "select p.parkImage,p.parkTitle,p.parkingAvailable,p.parkNoOfPlace,s.toTime,u.user_nom,p.parkAddress,p.parkLandmark,p.shelter from keepersSchedule k left outer join parkDetails p on k.parkIdFk = p.parkId left outer join user_details u on k.keeperIdFk = u.userid left outer join shiftMaster s on s.shiftMasterId = k.shiftMasterIdFk where k.keepersScheduleId = '" + event['params']['querystring']['keepersScheduleId'] + "'";
connection.query(sql, function (err, result) {
if (err) {
var response = {
"status": "ERROR",
"statusCode": "201",
"message": "Fail to execute the query",
"data": result
}
callback(response);
}
else {
if (result.length > 0) {
var message = 'vote mastere details retrived successfully !';
var status = 'OK';
var statusCode = '200';
} else {
var message = 'requested vote mastere details not found';
var status = 'ERROR';
var statusCode = '201';
}
var response = {
"status": status,
"statusCode": statusCode,
"message": message,
"data": result
}
callback(response);
}
});
}
else {
var response = {
"status": "ERROR",
"statusCode": "201",
"message": "Schedule id missing",
"data": result
}
callback(response);
}
};
exports.closeDbConnection = function (event, callback) {
connection.end();
callback({ 'status': 'OK' });
};
exports.handler = function (event, context) {
exports.connectWkDatabase(event, function (res) {
var httpMethod = event['context']['http-method'];
var postData = event['body-json'];
if (httpMethod == 'GET') {
exports.getParkinfo(event, function (outputResponse) {
exports.closeDbConnection(event, function (res) {
console.log(outputResponse);
context.done(null, outputResponse);
});
});
}
});
};