CrashLogJob.php 838 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://doc.hyperf.io
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
  10. */
  11. namespace App\Jobs;
  12. use App\Model\Mongo\CrashLogModel;
  13. use Hyperf\AsyncQueue\Job;
  14. class CrashLogJob extends Job
  15. {
  16. public $params;
  17. public function __construct($params)
  18. {
  19. // 这里最好是普通数据,不要使用携带 IO 的对象,比如 PDO 对象
  20. $this->params = $params;
  21. }
  22. public function handle()
  23. {
  24. try {
  25. make(CrashLogModel::class)->db()->insertOne(
  26. $this->params
  27. );
  28. } catch (\Exception $exception) {
  29. logger('CrashLogJob', [$exception->getMessage()]);
  30. }
  31. }
  32. }