CLASSFUNC BLOG
We Share Our Knowledge
Fix lỗi Enecolor sau khi trả lời Book không tạo được file pdf và tự động đặt hàng sách đến www.seichoku.com
Dam Van Duong
27 Th01 2021 12:55

Fix lỗi eneclor sau khi trả lời Book không tạo được file pdf và tự động đặt hàng sách đến https://www.seichoku.com/ sau khi trả lời xong.

Lỗi như sau:

image.png

Project Enecolor sử dụng Phantomjs để tạo crontab thực thi nhiệm vụ tạo file PDF và gửi file tới Seichoku đơn vị đặt sách thông qua API của Seichoku cung cấp. Kiểm tra file Task Common theo đường dẫn thư mục file: src/Shell/Task/QueueCommonTask.php

class QueueCommonTask extends QueueTask { public function runBatch($shell) { $now = new Time(); $HH_MM = $now->i18nFormat("HHmm"); $minute = $now->i18nFormat("mm"); if ($minute == "00" || $minute == "30") { $taskStepClass = 'QueueBatchStep'; $taskStep = $shell->{$taskStepClass}; $taskStep->main($HH_MM, $shell); $taskAutoClass = 'QueueBatchAuto'; $taskAuto = $shell->{$taskAutoClass}; $taskAuto->main($HH_MM, $shell); $taskStandardClass = 'QueueBatchStandard'; $taskAuto = $shell->{$taskStandardClass}; $taskAuto->main($HH_MM, $shell); } // 送信結果反映バッチ if ($minute == "10" || $minute == "40") { $taskSentMailClass = 'QueueBatchGetSentMailResult'; $taskStep = $shell->{$taskSentMailClass}; $taskStep->main(); } if ($minute == "45") { // PDF生成処理〜原稿登録バッチ $taskEnecolorBookClass = 'QueueBatchEnecolorBook'; $task = $shell->{$taskEnecolorBookClass}; $task->main($now); } if ($minute == "00") { // 統計バッチ // 統計バッチは1時間ごとに実行する。 $taskStatisticsClass = 'QueueBatchStatistics'; $task = $shell->{$taskStatisticsClass}; $task->main($HH_MM, $shell); } return true; } }

Trước tiên cần truy cập vào server "Enecolor-Prod-Batch-env" qua SSH:

cd .ssh && sudo ssh -i "Enecolor-Production.pem" ec2-user@ec2-54-199-180-185.ap-northeast-1.compute.amazonaws.com

Sử dụng lệnh để tạo bằng tay setting crontab Phantomjs.

crontab -e

để kiểm tra thông tin cài đặt của phantomjs, nếu không có dữ liệu tiến hành điền thông số sau và save lại

* * * * * cd /var/www/html && sudo chmod -R 777 /var/www/html/bin/cake && sudo chmod -R 777 /var/www/html/tmp/cache/models && bin/cake mail_queue runworker

Nhấn ESC, :x để lưu và thoát.

Restat lại Ec2 "Enecolor-Prod-Batch-env".

Ngoài ra, cần kiểm tra lại việc gọi lên API của Seichoku xem có thành công không? Các API cần lưu ý:

Đăng kí in sách với Seichoku https://www.seichoku.com/user_data/registerDraft.php

Sau khi đăng kí thành công, phía Seichoku sẽ tiến hành duyệt đơn đăng kí và sẽ phản hồi kết quả về webhooks :

https://enecolor-batch.geniam.com/api/v1/callback/book

Ví dụ request đăng kí đặt sách CURL :

curl --location --request POST 'https://www.seichoku.com/user_data/registerDraft.php' \ --header 'Content-Type: application/json' \ --header 'Cookie: [Cookie] \ --data-raw '{ "param": [Param] }'

Với param là Encode (https://www.base64decode.org/) từ :

{ 'testmode': 0, 'access_key': [AccessKeySeichokuAccount]', 'secret_key': [SecretKeySeichokuAccount]', 'customer_id': [ID], 'list': [ { 'path': '[path S3 File]', 'filename': '[fileNAME].pdf', 'easy': 0, 'nocover': 0, 'page_size': 4, 'niniwidth': null, 'niniheight': null, 'bind_type': 2, 'bind_direction': 2, 'paper_type': 11, 'text_color_type': 1, 'cover_paper_data': '101,2,1', 'cover_thick': 0, 'asobi': 0, 'uracover': '1', 'nuritasi': 1, 'zenmen': 0, 'rot_num': 1, 'hyousi_path': '[path S3 File]', 'hyousi_filename': '[fileNAME]_cover.png', }], }

API Document: 製本直送API仕様書1.3.3.pdf

Kiểm tra debug và error logs (cli-debug.log, cli-error.log) trong thư mục logs của thư mục :

cd /var/www/html/logs

Xong crontab sẽ thực hiện task và mỗi phút thứ 45 như trên cài đặt ở "QueueCommonTask.php", check log để kiểm tra nhé