Skip to content

Commit

Permalink
Merge pull request #196 from WebFiori/dev
Browse files Browse the repository at this point in the history
Added Support for Showing Stack Trace for Tasks
  • Loading branch information
usernane authored Oct 17, 2023
2 parents ad52401 + 18f9546 commit 7b4c282
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"webfiori/jsonx":"v3.3.0",
"webfiori/ui":"v2.5.6",
"webfiori/collections":"v1.1.3",
"webfiori/database":"v0.8.3",
"webfiori/database":"v0.8.4",
"webfiori/cli":"v1.1.3",
"webfiori/mailer":"v1.1.1",
"webfiori/err":"v1.0.6"
Expand Down
34 changes: 23 additions & 11 deletions tests/webfiori/framework/test/cli/SchedulerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function test05() {
'p' => '123456'
]);
$this->assertEquals(0, $runner->start());
$this->assertEquals([
$expected = [
"Select one of the scheduled tasks to force:\n",
"0: Fail 1\n",
"1: Fail 2\n",
Expand All @@ -169,16 +169,28 @@ public function test05() {
"Exception message: Call to undefined method app\\tasks\Fail2TestTask::undefined()\n",
"Thrown in: Fail2TestTask\n",
"Line: 44\n",
"Calling the method app\\tasks\Fail2TestTask::onFail()\n",
"Calling the method app\\tasks\Fail2TestTask::afterExec()\n",
"Check finished.\n",
"Total number of tasks: 5\n",
"Executed Tasks: 1\n",
"Successfully finished tasks:\n",
" <NONE>\n",
"Failed tasks:\n",
" Fail 2\n"
], $runner->getOutput());
"Stack Trace:\n",
"#0 At class app\\tasks\Fail2TestTask line 1083\n",
"#1 At class webfiori\\framework\scheduler\AbstractTask line 406\n",
"#2 At class webfiori\\framework\scheduler\AbstractTask line 904\n",
"#3 At class webfiori\\framework\scheduler\TasksManager line 600\n",
"#4 At class webfiori\\framework\scheduler\TasksManager line 135\n",
"#5 At class webfiori\\framework\cli\commands\SchedulerCommand line 86\n",
"#6 At class webfiori\\framework\cli\commands\SchedulerCommand line 328\n",
"#7 At class webfiori\\cli\CLICommand line 409\n",
"#8 At class webfiori\\cli\Runner line 684\n",
"#9 At class webfiori\\cli\Runner line 615\n",
"#10 At class webfiori\cli\Runner line 154\n",
"Skip"];
$actual = $runner->getOutput();
$idx = 0;
foreach ($expected as $item) {
if ($item == 'Skip') {
break;
}
$this->assertEquals($item, $actual[$idx]);
$idx++;
}
}
/**
* @test
Expand Down
8 changes: 8 additions & 0 deletions webfiori/framework/scheduler/AbstractTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Exception;
use Throwable;
use webfiori\collections\Queue;
use webfiori\error\TraceEntry;
use webfiori\framework\cli\commands\SchedulerCommand;
use webfiori\framework\exceptions\InvalidCRONExprException;
use webfiori\framework\Util;
Expand Down Expand Up @@ -1504,7 +1505,14 @@ private function logExeException(Throwable $ex, string $meth = '') {
TasksManager::log('Exception message: '.$ex->getMessage());
TasksManager::log('Thrown in: '.Util::extractClassName($ex->getFile()));
TasksManager::log('Line: '.$ex->getLine());
TasksManager::log('Stack Trace:');
$index = 0;

foreach ($ex->getTrace() as $traceEntry) {
$e = new TraceEntry($traceEntry);
TasksManager::log('#'.$index.' '.$e);
$index++;
}

if ($meth == 'execute') {
$this->isSuccess = false;
Expand Down

0 comments on commit 7b4c282

Please sign in to comment.