Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dp-ifacesoft committed Sep 30, 2020
1 parent d87cf66 commit 61ae499
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
16 changes: 16 additions & 0 deletions config/Ice/Core/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@
]
]
],
'ice_worker_status' => [
'route' => '/worker/{$worker_key}/status',
'params' => [
'worker_key' => '(\d+)'
],
'request' => [
'GET' => [
'actionClass' => 'Ice:Worker_Status',
'response' => ['contentType' => 'json']
],
'POST' => [
'actionClass' => 'Ice:Worker_Status',
'response' => ['contentType' => 'json']
],
],
],
'_Security' => '/security',
'_Private' => '/private',
'_CKEditor' => '/ckeditor',
Expand Down
32 changes: 32 additions & 0 deletions source/Ice/Action/Worker/Status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Ice\Action;

use Ice\Core\Action;
use Ice\DataProvider\Cli;
use Ice\DataProvider\Redis;
use Ice\DataProvider\Request;
use Ice\DataProvider\Router;

class Worker_Status extends Action
{
/**
* @return array
*/
protected static function config()
{
$config = parent::config();

$config['input']['worker_key'] = ['providers' => ['default', Router::class, Cli::class]];
$config['input']['action'] = ['providers' => ['default', Request::class, Cli::class]];

return $config;
}

public function run(array $input)
{
$provider = Redis::getInstance('default', $input['action']);

return $provider->hGet($input['worker_key']);
}
}
4 changes: 4 additions & 0 deletions source/Ice/Core/Action/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private function getWorkerKey($async = null)
/**
* @param array $dispatchWorker
* @param array $params
* @return array
* @throws Config_Error
* @throws Error
* @throws Exception
Expand All @@ -140,6 +141,8 @@ private function dispatch(array $dispatchWorker, array $params)
$tasks = (array)$this->getAllTasks(array_merge($params, $dispatchWorker));

$dispatchWorker['tasks'] = count($tasks);
$dispatchWorker['completed'] = 0;
$dispatchWorker['leftTime'] = '';

$workerKey = $dispatchWorker['workerKey'];

Expand Down Expand Up @@ -201,6 +204,7 @@ private function dispatch(array $dispatchWorker, array $params)

Logger::log('[ ' . $i . '/' . $dispatchWorker['tasks'] . ' : ' . $leftTasks . ' ] #' . $hash . ' ' . $taskLog . ' [left: ' . $leftTime . ']', get_class($this));

$provider->hSet($workerKey, ['completed' => $i, 'leftTime' => $leftTime]);

if ($isLastTask) {
Logger::log('Finishing..', get_class($this));
Expand Down

0 comments on commit 61ae499

Please sign in to comment.