AddRegisterJob.php 831 B

12345678910111213141516171819202122232425262728293031323334353637
  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\RegisterModel;
  13. use Hyperf\AsyncQueue\Job;
  14. class AddRegisterJob 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(RegisterModel::class)->db()
  26. ->insertOne($this->params);
  27. } catch (\Exception $exception) {
  28. logger('AddRegisterJob', [$exception->getMessage()]);
  29. }
  30. }
  31. }