Bug: catch excrption request to engine fail

CR: sonhh (fake)
This commit is contained in:
dongpd 2021-08-26 16:51:36 +07:00
parent b207d54462
commit 14467d53b5
10 changed files with 124 additions and 79 deletions

View File

@ -86,7 +86,7 @@ class ApiController extends Controller {
$ip = $server_ip->data;
if ($this->is_connected() && $logs) {
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 209;
$id_camera = 0;
if ($device_id)
$id_camera = intval($device_id->data);
$logsInfo = CaptureLogs::findOne($logs);
@ -260,7 +260,7 @@ class ApiController extends Controller {
]);
$updating = \app\models\SyncUrl::findOne(['key_config' => 'updating']);
}
$currentCache = json_decode(file_get_contents("http://localhost:2305/current-cache"), true);
$currentCache = json_decode(@file_get_contents("http://localhost:2305/current-cache"), true);
if ($updating->data === "true") {
if ($currentCache['n_128'] == $currentCache['n_512']) {
$updating->data = "false";
@ -295,12 +295,15 @@ class ApiController extends Controller {
foreach ($images as $k => $v) {
if (!isset($v['features512']) || (isset($v['features512']) && count($v['features512']) == 0)) {
$start = $this->getCurrentTime();
$features = json_decode(common::requestToEngine("/get-feature", [
$features = common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $v['url'], "type" => "raw"]
],
"type" => "512"
]), true);
]);
if (!$features['status'])
return ["status" => false];
$features = json_decode($features['data'], true);
$finish = $this->getCurrentTime();
$temp[] = round(($finish - $start), 4);
$v['features512'] = $features['results'][0]['feature512'];
@ -320,7 +323,7 @@ class ApiController extends Controller {
}
}
file_get_contents("http://localhost:2305/update-feature");
@file_get_contents("http://localhost:2305/update-feature");
$updating->data = "false";
$updating->save();
return ["status" => true];
@ -334,7 +337,7 @@ class ApiController extends Controller {
if ($server_ip)
$ip = $server_ip->data;
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 209;
$id_camera = 0;
if ($device_id)
$id_camera = intval($device_id->data);
$ls = CaptureLogs::find()->andWhere(['sync_status' => null])->all();
@ -400,7 +403,7 @@ class ApiController extends Controller {
}
public function actionCurrentCache() {
return file_get_contents("http://localhost:2305/current-cache");
return @file_get_contents("http://localhost:2305/current-cache");
}
public function actionSaveToken() {
@ -504,13 +507,15 @@ class ApiController extends Controller {
}
public function actionCheckLogs() {
Yii::$app->response->format = "json";
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "https://dev-dc.beetai.com";
if ($server_ip)
$ip = $server_ip->data;
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 209;
if ($device_id)
if (!$device_id)
return ["data" => "check logs fail"];
$id_camera = intval($device_id->data);
$datas = json_decode(file_get_contents($ip . "/api/model/get_log_model", false, stream_context_create([
@ -562,9 +567,8 @@ class ApiController extends Controller {
])
]
]));
file_get_contents("http://localhost:2305/update-feature?total=" . ListManagement::find()->count());
@file_get_contents("http://localhost:2305/update-feature?total=" . ListManagement::find()->count());
}
Yii::$app->response->format = "json";
return ["data" => "check logs"];
}
@ -597,12 +601,15 @@ class ApiController extends Controller {
if (!$this->resizeImg($img, $fileTarget)) {
file_put_contents($fileTarget, $img);
}
$features = json_decode(common::requestToEngine("/get-feature", [
$features = common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
],
"type" => "128"
]), true);
]);
if (!$features['status'])
return false;
$features = json_decode($features['data'], true);
$ft[] = [
"serverKey" => $files_name,
"url" => $fileName,

View File

@ -297,6 +297,38 @@ class ConfigController extends Controller {
public function actionReset() {
if (Yii::$app->request->post()) {
if (Yii::$app->request->post("deleteDB") === "true") {
\Yii::$app->db->createCommand()->truncateTable('capture_logs')->execute();
\Yii::$app->db->createCommand()->truncateTable('list_management')->execute();
array_map('unlink', glob("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/*.*"));
try {
file_get_contents("http://localhost:2305/update-feature");
} catch (\Exception $exc) {
}
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "https://dev-dc.beetai.com";
if ($server_ip)
$ip = $server_ip->data;
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 0;
if ($device_id)
$id_camera = intval($device_id->data);
try {
file_get_contents($ip . "/api/model/reset_log_model", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
"idCamera" => $id_camera,
"isCloud" => 0
])
]
]));
} catch (Exception $ex) {
}
}
if (Yii::$app->request->post("resetDevice") === "true") {
$tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([
'http' => [
@ -328,39 +360,8 @@ class ConfigController extends Controller {
]
]));
}
if (Yii::$app->request->post("deleteDB") === "true") {
\Yii::$app->db->createCommand()->truncateTable('capture_logs')->execute();
\Yii::$app->db->createCommand()->truncateTable('list_management')->execute();
array_map('unlink', glob("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/*.*"));
try {
file_get_contents("http://localhost:2305/update-feature");
} catch (\Exception $exc) {
}
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "https://dev-dc.beetai.com";
if ($server_ip)
$ip = $server_ip->data;
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 209;
if ($device_id)
$id_camera = intval($device_id->data);
try {
file_get_contents($ip . "/api/model/reset_log_model", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
"idCamera" => $id_camera,
"isCloud" => 0
])
]
]));
} catch (Exception $ex) {
}
}
return Url::to(['/config']);
\app\models\SyncUrl::deleteAll(['IN', 'key_config', ['server_api', 'device_id']]);
return Url::to(['/config/cau-hinh-thiet-bi']);
} else {
Yii::$app->response->format = "json";
return [
@ -434,7 +435,7 @@ class ConfigController extends Controller {
$model = new \app\models\SyncUrl();
$model->create([
'key_config' => 'device_id',
'data' => $engineConfig['data']['engines'][0]['id']
'data' => strval($engineConfig['data']['engines'][0]['id'])
]);
}
return $this->render('device', [

View File

@ -100,11 +100,14 @@ class ControlLogsController extends Controller {
if (!$this->resizeImg($img, $fileTarget))
$fileName = $url;
$features = json_decode(common::requestToEngine("/get-feature", [
$features = common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
]
]), true);
]);
if (!$features['status'])
return ["status" => false, "text" => Yii::t("app", "ENGINE_KHONG_HOAT_DONG")];
$features = json_decode($features['data'], true);
$images[] = [
"url" => $fileName,
"urlOld" => $url,

View File

@ -97,11 +97,14 @@ class ListManagementController extends Controller {
$check = ListManagement::findOne(['code' => $data['code']]);
if ($check)
return ["status" => false];
$features = json_decode(common::requestToEngine("/get-feature", [
$features = common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $data['image'], "type" => "raw"]
]
]), true);
]);
if (!$features['status'])
return ["status" => false];
$features = json_decode($features['data'], true);
$data['image'] = json_encode([
[
"url" => $data['image'],
@ -141,11 +144,14 @@ class ListManagementController extends Controller {
if (!$this->resizeImg($img, $fileTarget))
$fileName = $url;
$features = json_decode(common::requestToEngine("/get-feature", [
$features = common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
]
]), true);
]);
if (!$features['status'])
return ["status" => false, "text" => Yii::t("app", "ENGINE_KHONG_HOAT_DONG")];
$features = json_decode($features['data'], true);
$images[] = [
"url" => $fileName,
"urlOld" => $url,
@ -181,11 +187,14 @@ class ListManagementController extends Controller {
if (!$this->resizeImg($img, $fileTarget))
$fileName = $url;
$features = json_decode(common::requestToEngine("/get-feature", [
$features = common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
]
]), true);
]);
if (!$features['status'])
return ["status" => false, "text" => Yii::t("app", "ENGINE_KHONG_HOAT_DONG")];
$features = json_decode($features['data'], true);
$data['image'] = json_encode([
[
"url" => $fileName,
@ -239,11 +248,14 @@ class ListManagementController extends Controller {
if (!$this->resizeImg($img, $fileTarget))
$fileName = $data['image'];
$features = json_decode(common::requestToEngine("/get-feature", [
$features = common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
]
]), true);
]);
if (!$features['status'])
return ["status" => false, "text" => Yii::t("app", "ENGINE_KHONG_HOAT_DONG")];
$features = json_decode($features['data'], true);
$images = json_decode($model->image, true);
$images[] = [
"url" => $fileName,
@ -357,11 +369,14 @@ class ListManagementController extends Controller {
$model = new common();
Yii::$app->response->format = "json";
$url = $model->UploadFile("AnhNhanVien", ["PNG", "JPG", "JPEG", "GIF"], "temp");
$features = json_decode(common::requestToEngine("/get-feature", [
$features = common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/" . $url, "type" => "crop"]
]
]), true);
]);
if (!$features['status'])
return ["status" => false];
$features = json_decode($features['data'], true);
unlink("/var/www/html/BiFace_Server_Lite/web/" . $url);
if ($features['results'][0]['crop'] === "") {
return ["status" => false];
@ -411,7 +426,7 @@ class ListManagementController extends Controller {
if ($server_ip)
$ip = $server_ip->data;
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 209;
$id_camera = 0;
if ($device_id)
$id_camera = intval($device_id->data);
@ -483,12 +498,15 @@ class ListManagementController extends Controller {
$finish = $this->getCurrentTime();
$temp["saveIMG"] = round(($finish - $start), 4);
$start = $this->getCurrentTime();
$features = json_decode(common::requestToEngine("/get-feature", [
$features = common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
],
"type" => "128"
]), true);
]);
if (!$features['status'])
return false;
$features = json_decode($features['data'], true);
$finish = $this->getCurrentTime();
$temp["extract"] = round(($finish - $start), 4);
$ft[] = [
@ -525,6 +543,8 @@ class ListManagementController extends Controller {
if ($model) {
if (isset($data['images'])) {
$extractFeature = $this->extractFeature($data['images'], $data['files_name'], $data['id'], json_decode($model->image, true));
if (!$extractFeature)
return false;
$processTime["extractFeature"] = $extractFeature['time'];
$ft = $extractFeature['features'];
}
@ -545,6 +565,8 @@ class ListManagementController extends Controller {
} else {
if (isset($data['images'])) {
$extractFeature = $this->extractFeature($data['images'], $data['files_name'], $data['id']);
if (!$extractFeature)
return false;
$processTime["extractFeature"] = $extractFeature['time'];
$ft = $extractFeature['features'];
}
@ -704,7 +726,7 @@ class ListManagementController extends Controller {
if ($server_ip)
$ip = $server_ip->data;
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 209;
$id_camera = 0;
if ($device_id)
$id_camera = intval($device_id->data);

View File

@ -130,5 +130,6 @@ return [
"DOI_MAT_KHAU_THANH_CONG" => "Change password successfully",
"DANG_XU_LY" => "Loading ...",
"THONG_BAO" => "Notify",
"CO_LOI_XAY_RA_HAY_THU_LAI" => "An error occurred, check the network connection and try again"
"CO_LOI_XAY_RA_HAY_THU_LAI" => "An error occurred, check the network connection and try again",
"ENGINE_KHONG_HOAT_DONG" => "Engine is not running"
];

View File

@ -130,5 +130,6 @@ return [
"DOI_MAT_KHAU_THANH_CONG" => "パスワードを正常に変更する",
"DANG_XU_LY" => "処理中 ...",
"THONG_BAO" => "報告",
"CO_LOI_XAY_RA_HAY_THU_LAI" => "おそらくネットワーク接続が原因でエラーが発生しました。再試行してください"
"CO_LOI_XAY_RA_HAY_THU_LAI" => "おそらくネットワーク接続が原因でエラーが発生しました。再試行してください",
"ENGINE_KHONG_HOAT_DONG" => "Engine不活動"
];

View File

@ -130,5 +130,6 @@ return [
"DOI_MAT_KHAU_THANH_CONG" => "Đổi mật khẩu thành công",
"DANG_XU_LY" => "Đang xử lý ...",
"THONG_BAO" => "Thông báo",
"CO_LOI_XAY_RA_HAY_THU_LAI" => "Có lỗi xảy ra, có thể do đường truyền mạng, xin vui lòng thử lại"
"CO_LOI_XAY_RA_HAY_THU_LAI" => "Có lỗi xảy ra, có thể do đường truyền mạng, xin vui lòng thử lại",
"ENGINE_KHONG_HOAT_DONG" => "Engine không hoạt động"
];

View File

@ -172,17 +172,20 @@ class common extends \yii\db\ActiveRecord {
}
public static function requestToEngine($path, $data) {
return file_get_contents("http://localhost:2305" . $path, false, stream_context_create([
$content = @file_get_contents("http://localhost:2305" . $path, false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode($data)
]
]));
if ($content == false)
return ["status" => false];
return ["status" => true, "data" => $content];
}
public static function updateFeature($datas) {
return file_get_contents("http://localhost:2305/update-person", false, stream_context_create([
return @file_get_contents("http://localhost:2305/update-person", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",

View File

@ -29,6 +29,7 @@
<input type="hidden" name="DONG_BO_DU_LIEU_HOAN_THANH" value="{Yii::t("app", "DONG_BO_DU_LIEU_HOAN_THANH")}">
<input type="hidden" name="DA_THEM_HINH_ANH_MAU" value="{Yii::t("app", "DA_THEM_HINH_ANH_MAU")}">
<input type="hidden" name="CO_LOI_XAY_RA_HAY_THU_LAI" value="{Yii::t("app", "CO_LOI_XAY_RA_HAY_THU_LAI")}">
<input type="hidden" name="ENGINE_KHONG_HOAT_DONG" value="{Yii::t("app", "ENGINE_KHONG_HOAT_DONG")}">
<div id="blocking" class="fade modal" role="dialog" tabindex="-1">
<div class="modal-dialog" style="top: 50%;margin-top: -45px;">

View File

@ -465,6 +465,11 @@ function syncFeature(id, fullData) {
totals: totals
},
success: function (data) {
if (!data) {
common.modalBlock(false);
common.modalAlert($("input[name='ENGINE_KHONG_HOAT_DONG']").val(), "danger", "");
return;
}
console.log(data, progress);
progress++;
$("#progress-current").html(parseInt($("#progress-current").html()) + 1);