-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added schedule record for telescope (#799)
- Loading branch information
Showing
9 changed files
with
108 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of friendsofhyperf/components. | ||
* | ||
* @link https://github.com/friendsofhyperf/components | ||
* @document https://github.com/friendsofhyperf/components/blob/main/README.md | ||
* @contact huangdijia@gmail.com | ||
*/ | ||
|
||
namespace FriendsOfHyperf\Telescope\Controller; | ||
|
||
use FriendsOfHyperf\Telescope\EntryType; | ||
|
||
class ScheduleController extends EntryController | ||
{ | ||
/** | ||
* The entry type for the controller. | ||
* | ||
* @return string | ||
*/ | ||
protected function entryType() | ||
{ | ||
return EntryType::SCHEDULE; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of friendsofhyperf/components. | ||
* | ||
* @link https://github.com/friendsofhyperf/components | ||
* @document https://github.com/friendsofhyperf/components/blob/main/README.md | ||
* @contact huangdijia@gmail.com | ||
*/ | ||
|
||
namespace FriendsOfHyperf\Telescope\Listener; | ||
|
||
use FriendsOfHyperf\Telescope\IncomingEntry; | ||
use FriendsOfHyperf\Telescope\Telescope; | ||
use FriendsOfHyperf\Telescope\TelescopeConfig; | ||
use FriendsOfHyperf\Telescope\TelescopeContext; | ||
use Hyperf\Crontab\Event; | ||
use Hyperf\Event\Contract\ListenerInterface; | ||
|
||
class CronEventListener implements ListenerInterface | ||
{ | ||
public function __construct( | ||
private TelescopeConfig $telescopeConfig | ||
) { | ||
} | ||
|
||
public function listen(): array | ||
{ | ||
return [ | ||
Event\AfterExecute::class, | ||
Event\FailToExecute::class, | ||
]; | ||
} | ||
|
||
/** | ||
* @param Event\AfterExecute|Event\FailToExecute|object $event | ||
*/ | ||
public function process(object $event): void | ||
{ | ||
if (! $this->telescopeConfig->isEnable('schedule')) { | ||
return; | ||
} | ||
|
||
TelescopeContext::getOrSetBatch(); | ||
|
||
$output = match (true) { | ||
$event instanceof Event\AfterExecute => 'success', | ||
$event instanceof Event\FailToExecute => '[fail]' . (string) $event->getThrowable(), | ||
default => '', | ||
}; | ||
|
||
Telescope::recordSchedule(IncomingEntry::make([ | ||
'command' => $event->crontab->getName(), | ||
'description' => $event->crontab->getMemo(), | ||
'expression' => $event->crontab->getRule(), | ||
'timezone' => $event->crontab->getTimezone(), | ||
'user' => '', | ||
'output' => $output, | ||
])); | ||
} | ||
} |
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