<?php

declare(strict_types=1);

namespace App\Service;

use App\Job\ExampleJob;
use Hyperf\AsyncQueue\Driver\DriverFactory;
use Hyperf\AsyncQueue\Driver\DriverInterface;

class QueueService
{
    /**
     * @var DriverInterface
     */
    protected $driver;

    public function __construct(DriverFactory $driverFactory)
    {
        $this->driver = $driverFactory->get('default');
    }

    /**
     * 生产消息.
     * @param $params 数据
     * @param int $delay 延时时间 单位秒
     */
    public function push($params, int $delay = 0): bool
    {
        return $this->driver->push(new ExampleJob($params), $delay);
    }

    /**
     * 队列详情信息.
     * @param int $delay 延时时间 单位秒
     */
    public function info(): array
    {
        return $this->driver->info();
    }

    public function pop(): array
    {
        return $this->driver->pop();
    }
}