-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #848 from algolia/develop
Develop
- Loading branch information
Showing
32 changed files
with
523 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/code/community/Algolia/Algoliasearch/controllers/Adminhtml/QueueController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
class Algolia_Algoliasearch_Adminhtml_QueueController extends Mage_Adminhtml_Controller_Action | ||
{ | ||
public function indexAction() | ||
{ | ||
/** @var Algolia_Algoliasearch_Helper_Config $config */ | ||
$config = Mage::helper('algoliasearch/config'); | ||
|
||
/** @var Mage_Core_Model_Resource $resource */ | ||
$resource = Mage::getSingleton('core/resource'); | ||
$tableName = $resource->getTableName('algoliasearch/queue'); | ||
|
||
$readConnection = $resource->getConnection('core_read'); | ||
|
||
$size = (int) $readConnection->query('SELECT COUNT(*) as total_count FROM '.$tableName)->fetchColumn(0); | ||
$maxJobsPerSingleRun = $config->getNumberOfJobToRun(); | ||
|
||
$etaMinutes = ceil($size / $maxJobsPerSingleRun) * 5; // 5 - assuming the queue runner runs every 5 minutes | ||
|
||
$eta = $etaMinutes . ' minutes'; | ||
if ($etaMinutes > 60) { | ||
$hours = floor($etaMinutes / 60); | ||
$restMinutes = $etaMinutes % 60; | ||
|
||
$eta = $hours . ' hours ' . $restMinutes . ' minutes'; | ||
} | ||
|
||
$queueInfo = array( | ||
'isEnabled' => $config->isQueueActive(), | ||
'currentSize' => $size, | ||
'eta' => $eta, | ||
); | ||
|
||
$this->sendResponse($queueInfo); | ||
} | ||
|
||
public function truncateAction() | ||
{ | ||
/** @var Mage_Core_Model_Resource $resource */ | ||
$resource = Mage::getSingleton('core/resource'); | ||
$tableName = $resource->getTableName('algoliasearch/queue'); | ||
|
||
try { | ||
$writeConnection = $resource->getConnection('core_write'); | ||
$writeConnection->query('TRUNCATE TABLE '.$tableName); | ||
|
||
$status = array('status' => 'ok'); | ||
} catch (\Exception $e) { | ||
$status = array('status' => 'ko', 'message' => $e->getMessage()); | ||
} | ||
|
||
$this->sendResponse($status); | ||
} | ||
|
||
private function sendResponse($data) | ||
{ | ||
$this->getResponse()->setHeader('Content-Type', 'application/json'); | ||
$this->getResponse()->setBody(json_encode($data)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.