正在显示
4 个修改的文件
包含
64 行增加
和
6 行删除
| @@ -23,7 +23,11 @@ | @@ -23,7 +23,11 @@ | ||
| 23 | }, | 23 | }, |
| 24 | "require": { | 24 | "require": { |
| 25 | "php": ">=7.4", | 25 | "php": ">=7.4", |
| 26 | - "wujunze/dingtalk-exception": "^2.2" | 26 | + "wujunze/dingtalk-exception": "^2.2", |
| 27 | + "illuminate/queue":"^8.0", | ||
| 28 | + "illuminate/support": "^8.0", | ||
| 29 | + "illuminate/bus": "^8.0", | ||
| 30 | + "monolog/monolog": "^2.0" | ||
| 27 | }, | 31 | }, |
| 28 | "require-dev": { | 32 | "require-dev": { |
| 29 | "phpunit/phpunit": "^9.5.10", | 33 | "phpunit/phpunit": "^9.5.10", |
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | -use Lackoxygen\ExceptionPush\Agents\{Ding, Wx}; | 3 | +use Lackoxygen\ExceptionPush\Agents\Ding; |
| 4 | +use Lackoxygen\ExceptionPush\Agents\Wx; | ||
| 4 | 5 | ||
| 5 | return [ | 6 | return [ |
| 6 | 'agents' => [ | 7 | 'agents' => [ |
| @@ -12,10 +13,10 @@ return [ | @@ -12,10 +13,10 @@ return [ | ||
| 12 | ], | 13 | ], |
| 13 | 14 | ||
| 14 | 'client' => [ | 15 | 'client' => [ |
| 15 | - 'timeout' => 30.00, | 16 | + 'timeout' => 5.00, |
| 16 | ], | 17 | ], |
| 17 | 18 | ||
| 18 | 'callbacks' => [ | 19 | 'callbacks' => [ |
| 19 | - 'formatter' => null, 'dispatcher' => null | 20 | + 'formatter' => null, 'dispatcher' => 'Lackoxygen\ExceptionPush\Job::push' |
| 20 | ] | 21 | ] |
| 21 | ]; | 22 | ]; |
| @@ -30,8 +30,7 @@ class Dispatcher implements CallbackInterface | @@ -30,8 +30,7 @@ class Dispatcher implements CallbackInterface | ||
| 30 | } | 30 | } |
| 31 | try { | 31 | try { |
| 32 | $agent->report($body); | 32 | $agent->report($body); |
| 33 | - } catch (\Exception $exception) { | ||
| 34 | - app('log')->error($exception->getMessage()); | 33 | + } catch (\Throwable $exception) { |
| 35 | } | 34 | } |
| 36 | } | 35 | } |
| 37 | }; | 36 | }; |
src/Job/ExceptionPushJob.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace Lackoxygen\ExceptionPush\Job; | ||
| 4 | + | ||
| 5 | +use Illuminate\Bus\Queueable; | ||
| 6 | +use Illuminate\Contracts\Queue\ShouldQueue; | ||
| 7 | +use Illuminate\Foundation\Bus\Dispatchable; | ||
| 8 | +use Illuminate\Queue\InteractsWithQueue; | ||
| 9 | +use Illuminate\Queue\SerializesModels; | ||
| 10 | +use Lackoxygen\ExceptionPush\Dispatcher; | ||
| 11 | + | ||
| 12 | +class ExceptionPushJob implements ShouldQueue | ||
| 13 | +{ | ||
| 14 | + use Dispatchable; | ||
| 15 | + use InteractsWithQueue; | ||
| 16 | + use Queueable; | ||
| 17 | + use SerializesModels; | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + protected array $agents; | ||
| 21 | + | ||
| 22 | + protected array $traces; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * Create a new job instance. | ||
| 26 | + * | ||
| 27 | + * @return void | ||
| 28 | + */ | ||
| 29 | + public function __construct(array $agents, array $traces) | ||
| 30 | + { | ||
| 31 | + $this->agents = $agents; | ||
| 32 | + | ||
| 33 | + $this->traces = $traces; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * Execute the job. | ||
| 38 | + * | ||
| 39 | + * @return void | ||
| 40 | + */ | ||
| 41 | + public function handle() | ||
| 42 | + { | ||
| 43 | + $dispatcher = new Dispatcher(); | ||
| 44 | + | ||
| 45 | + $callback = $dispatcher->default(); | ||
| 46 | + | ||
| 47 | + $callback($this->agents, $this->traces); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public static function push() | ||
| 51 | + { | ||
| 52 | + static::dispatch(...func_get_args()); | ||
| 53 | + } | ||
| 54 | +} |
-
请 注册 或 登录 后发表评论