Skip to content

Commit

Permalink
Merge branch 'dp' into 1.24
Browse files Browse the repository at this point in the history
# Conflicts:
#	source/Ice/Core/WidgetComponent.php
  • Loading branch information
dp-ifacesoft committed Sep 22, 2020
2 parents 2f8354a + 76aa01f commit 16ba579
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
34 changes: 32 additions & 2 deletions source/Ice/Core/Action/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected static function config()
$config['input']['limit'] = ['providers' => ['default', Cli::class], 'default' => null];
$config['input']['report'] = ['providers' => ['default', Cli::class], 'default' => 0];
$config['input']['async'] = ['providers' => ['default', Cli::class], 'default' => 0];
$config['input']['isLastTask'] = ['providers' => ['default', Cli::class], 'default' => 0];

return $config;
}
Expand Down Expand Up @@ -63,6 +64,10 @@ final public function run(array $input)
if ($input['hash']) {
$this->task($workerKey, $input['hash']);

if ($input['isLastTask']) {
$this->finish($input);
}

return;
}

Expand Down Expand Up @@ -154,6 +159,10 @@ private function dispatch(array $dispatchWorker, array $params)

foreach ($tasks as $task) {
$i++;

$leftTasks = $dispatchWorker['tasks'] - $i;
$isLastTask = (int) !$leftTasks;

$worker = $provider->hGet($workerKey);

if ($dispatchWorker['started_at'] !== $worker['started_at']) {
Expand Down Expand Up @@ -190,8 +199,14 @@ private function dispatch(array $dispatchWorker, array $params)

$taskLog = Type_String::printR($task, false);

Logger::log('[ '. $i . '/' . $dispatchWorker['tasks'] .' : ' . ($dispatchWorker['tasks'] - $i) . ' ] #' . $hash .' ' . $taskLog . ' [left: ' . $leftTime . ']', get_class($this));
$class::call(['workerKey' => $workerKey, 'hash' => $hash, 'task' => $taskLog], 0, $bg);
Logger::log('[ ' . $i . '/' . $dispatchWorker['tasks'] . ' : ' . $leftTasks . ' ] #' . $hash . ' ' . $taskLog . ' [left: ' . $leftTime . ']', get_class($this));


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

$class::call(['workerKey' => $workerKey, 'hash' => $hash, 'task' => $taskLog, 'isLastTask' => $isLastTask], 0, $bg);
} catch (\Exception $e) {
$this->getLogger()->error(['Worker {$0}: Task #{$1} failed - {$2}', [get_class($this), $hash, Type_String::printR($task)]], __FILE__, __LINE__, $e);
} catch (\Throwable $e) {
Expand Down Expand Up @@ -276,4 +291,19 @@ protected function hit()
{
$this->getProvider()->getKeys();
}

/**
* @param array $input
* @return mixed
*/
private function finish(array $input)
{
$report = $this->flush($input);

Logger::log('Finish done.', get_class($this));

return $report;
}

abstract protected function flush(array $input);
}
2 changes: 1 addition & 1 deletion source/Ice/Core/WidgetComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected function setTemplateClass($templateClass)
? $widgetComponentClass::getConfig()->get('render/template', true)
: $templateClass;

if ($this->templateClass && is_array($this->templateClass) && $this->templateClass[0] === '_') {
if ($this->templateClass && is_string($this->templateClass) && $this->templateClass[0] == '_') {
$this->templateClass = $widgetComponentClass . $this->templateClass;
}

Expand Down

0 comments on commit 16ba579

Please sign in to comment.