jackyli86/resque-ext

基于 resque/php-resque 的一个扩展,使使用 resque/php-resque 更为简便

v1.0.2 2023-01-06 09:34 UTC

This package is auto-updated.

Last update: 2024-09-20 11:09:47 UTC


README

基于 resque/php-resque 的一个扩展,使使用 resque/php-resque 更为简便

如何使用

客户端使用

    // initialize resque client config
    // todo this must be first initialized before class ResqueClient functions
    $instance = ResqueClientConfig::instance();
    $instance->setRedisBackEnd('localhost');
    $instance->setRedisBackEndDb(0);

    // push job to queue
    ResqueClient::enqueue('test',job_echo::class, ['time' => date('Y-m-d H:i:s')]);

    // push job to queue at [time() + 60]
    ResqueClient::enqueueAt(time() + 60, 'test',job_echo::class, ['time' => date('Y-m-d H:i:s')]);

    // push job to queue after 60 seconds
    ResqueClient::enqueue(60 , 'test',job_echo::class, ['time' => date('Y-m-d H:i:s')]);

服务器使用

如果您只想运行一个工作进程,使用 ResqueServer 更为简单。

尽管 ResqueServer 更简单,但仍然建议您在将来需要快速扩展时使用 ResqueDeamon。

    // set server config
    $config = new ResqueServerConfig(true, ['test'], 1, 'localhost');

    // start up resque server, this will block the process
    ResqueServer::startup($config);

如果您需要运行多个 resque 服务,强烈推荐使用 ResqueDeamon。

    // set deamon configs
    $configs = [];
    // resque scheduler
    $configs[] = new ResqueServerConfig(false, ['test-01'], 1, 'localhost');

    // three workers 
    $configs[] = new ResqueServerConfig(true, ['test-01'], 1, 'localhost');
    $configs[] = new ResqueServerConfig(true, ['test-02'], 2, 'localhost');
    $configs[] = new ResqueServerConfig(true, ['test-03'], 3, 'localhost');


    // start up resque services
    ResqueDeamon::startup($configs);

    // shutdown resque services
    ResqueDeamon::shutdown($configs);

    // re start up resque services
    ResqueDeamon::restartup($configs);