From 61ae499a5ad4b0d687cdef162bcfaa539b07597a Mon Sep 17 00:00:00 2001 From: dp-ifacesoft Date: Wed, 30 Sep 2020 11:04:00 +0300 Subject: [PATCH] fix --- config/Ice/Core/Route.php | 16 +++++++++++++++ source/Ice/Action/Worker/Status.php | 32 +++++++++++++++++++++++++++++ source/Ice/Core/Action/Worker.php | 4 ++++ 3 files changed, 52 insertions(+) create mode 100644 source/Ice/Action/Worker/Status.php diff --git a/config/Ice/Core/Route.php b/config/Ice/Core/Route.php index b3e5b217..967a15f1 100644 --- a/config/Ice/Core/Route.php +++ b/config/Ice/Core/Route.php @@ -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', diff --git a/source/Ice/Action/Worker/Status.php b/source/Ice/Action/Worker/Status.php new file mode 100644 index 00000000..c7fd2dee --- /dev/null +++ b/source/Ice/Action/Worker/Status.php @@ -0,0 +1,32 @@ + ['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']); + } +} diff --git a/source/Ice/Core/Action/Worker.php b/source/Ice/Core/Action/Worker.php index 43e92a90..257067eb 100644 --- a/source/Ice/Core/Action/Worker.php +++ b/source/Ice/Core/Action/Worker.php @@ -129,6 +129,7 @@ private function getWorkerKey($async = null) /** * @param array $dispatchWorker * @param array $params + * @return array * @throws Config_Error * @throws Error * @throws Exception @@ -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']; @@ -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));