From 60ecfe2545a5f96ace0cad83728274817ad04965 Mon Sep 17 00:00:00 2001 From: Maxim Baibakov Date: Mon, 27 Aug 2018 10:37:28 +1000 Subject: [PATCH 1/4] Adding extra logging on import parts of the Cronjob Adding extra logging on import parts of the Cronjob. There is a bit lack of visibility around execution of the sync process. Would be awesome to see where the sync spends more time and helps to diagnose, if the sync stuck somewhere due to some reason. E.g. Reasons: - Payload was not able to generate due to M2 Core issue and failed with warning or fatal error - You can see how much time been spent on specific part e.g. products, orders and etc. It helped me to diagnose that cart generation was taking about 20 minutes to generate due to some slow SQL query --- Cron/Ecommerce.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Cron/Ecommerce.php b/Cron/Ecommerce.php index 33ab0d50..4b563a55 100644 --- a/Cron/Ecommerce.php +++ b/Cron/Ecommerce.php @@ -170,19 +170,30 @@ protected function _processStore($storeId, $mailchimpStoreId, $listId) $batchArray = []; $results = $this->_apiSubscribers->sendSubscribers($storeId, $listId); if ($this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_ECOMMERCE_ACTIVE, $storeId)) { + $this->_helper->log('Generate Products payload'); $products = $this->_apiProduct->_sendProducts($storeId); $countProducts = count($products); $results = array_merge($results, $products); + + $this->_helper->log('Generate Customers payload'); $customers = $this->_apiCustomer->sendCustomers($storeId); $countCustomers = count($customers); $results = array_merge($results, $customers); + + $this->_helper->log('Generate Orders payload'); $orders = $this->_apiOrder->sendOrders($storeId); $countOrders = count($orders); $results = array_merge($results, $orders); + + $this->_helper->log('Generate Carts payload'); $carts = $this->_apiCart->createBatchJson($storeId); $results = array_merge($results, $carts); + + $this->_helper->log('Generate Rules payload'); $rules = $this->_apiPromoRules->sendRules($storeId); $results = array_merge($results, $rules); + + $this->_helper->log('Generate Coupons payload'); $coupons = $this->_apiPromoCodes->sendCoupons($storeId); $results = array_merge($results, $coupons); } From c71529b3c416ee8f8d3c846ef21dd00b4b998770 Mon Sep 17 00:00:00 2001 From: Maxim Baibakov Date: Wed, 12 Sep 2018 10:39:07 +1000 Subject: [PATCH 2/4] Create temporary directory, if that does not exist Create temporary directory, if that does not exist to avoid error "Failed to open stream: No such file or directory" --- Model/Api/Result.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Model/Api/Result.php b/Model/Api/Result.php index 0f4b1ffa..8edf74bd 100644 --- a/Model/Api/Result.php +++ b/Model/Api/Result.php @@ -95,6 +95,11 @@ public function getBatchResponse($batchId, $storeId = null) $response = $api->batchOperation->status($batchId); if (isset($response['status']) && $response['status'] == 'finished') { + // Create temporary directory, if that does not exist + if (!is_dir($baseDir . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . self::MAILCHIMP_TEMP_DIR)) { + mkdir($baseDir . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . self::MAILCHIMP_TEMP_DIR); + } + // get the tar.gz file with the results $fileUrl = urldecode($response['response_body_url']); $fileName = $baseDir . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . self::MAILCHIMP_TEMP_DIR . DIRECTORY_SEPARATOR . $batchId; From 94041ea48c449173ef5e323a5aee51c91dce4604 Mon Sep 17 00:00:00 2001 From: Maxim Baibakov Date: Thu, 13 Sep 2018 20:35:16 +1000 Subject: [PATCH 3/4] Update Result.php --- Model/Api/Result.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Model/Api/Result.php b/Model/Api/Result.php index 8edf74bd..c7245eb7 100644 --- a/Model/Api/Result.php +++ b/Model/Api/Result.php @@ -95,10 +95,6 @@ public function getBatchResponse($batchId, $storeId = null) $response = $api->batchOperation->status($batchId); if (isset($response['status']) && $response['status'] == 'finished') { - // Create temporary directory, if that does not exist - if (!is_dir($baseDir . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . self::MAILCHIMP_TEMP_DIR)) { - mkdir($baseDir . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . self::MAILCHIMP_TEMP_DIR); - } // get the tar.gz file with the results $fileUrl = urldecode($response['response_body_url']); From d9c7d7cada19b185cb096bd8acef27bdb51bdc54 Mon Sep 17 00:00:00 2001 From: Maxim Baibakov Date: Thu, 13 Sep 2018 20:35:35 +1000 Subject: [PATCH 4/4] Update Result.php --- Model/Api/Result.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Model/Api/Result.php b/Model/Api/Result.php index c7245eb7..0f4b1ffa 100644 --- a/Model/Api/Result.php +++ b/Model/Api/Result.php @@ -95,7 +95,6 @@ public function getBatchResponse($batchId, $storeId = null) $response = $api->batchOperation->status($batchId); if (isset($response['status']) && $response['status'] == 'finished') { - // get the tar.gz file with the results $fileUrl = urldecode($response['response_body_url']); $fileName = $baseDir . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . self::MAILCHIMP_TEMP_DIR . DIRECTORY_SEPARATOR . $batchId;