GithubHelp home page GithubHelp logo

php-resque's Introduction

PHP Resque Worker (and Enqueue)

PHP Resque is a Redis-backed library for creating background jobs, placing those jobs on one or more queues, and processing them later.

PHP-Resque Logo

License (MIT) PHP Version Latest Version Latest Unstable Version Downloads

Build Status Dependency Status

Latest Release Latest Release Date Commits Since Latest Release Maintenance Status

Contributors Chat on Slack

Background

Resque was pioneered by GitHub, and written in Ruby. What you're seeing here started life as an almost direct port of the Resque worker and enqueue system to PHP.

For more information on Resque, visit the official GitHub project: https://github.com/resque/resque

For further information, see the launch post on the GitHub blog: http://github.com/blog/542-introducing-resque

The PHP port does NOT include its own web interface for viewing queue stats, as the data is stored in the exact same expected format as the Ruby version of Resque.

The PHP port provides much the same features as the Ruby version:

  • Workers can be distributed between multiple machines
  • Includes support for priorities (queues)
  • Resilient to memory leaks (forking)
  • Expects failure

It also supports the following additional features:

  • Has the ability to track the status of jobs
  • Will mark a job as failed, if a forked child running a job does not exit with a status code as 0
  • Has built in support for setUp and tearDown methods, called pre and post jobs

Additionally it includes php-resque-scheduler, a PHP port of resque-scheduler, which adds support for scheduling items in the future to Resque. It has been designed to be an almost direct-copy of the Ruby plugin

At the moment, php-resque-scheduler only supports delayed jobs, which is the ability to push a job to the queue and have it run at a certain timestamp, or in a number of seconds. Support for recurring jobs (similar to CRON) is planned for a future release.

This port was originally made by Chris Boulton, with maintenance by the community. See https://github.com/chrisboulton/php-resque for more on that history.

Requirements

  • PHP 5.3+
  • Redis 2.2+
  • Optional but Recommended: Composer

Getting Started

The easiest way to work with php-resque is when it's installed as a Composer package inside your project. Composer isn't strictly required, but makes life a lot easier.

If you're not familiar with Composer, please see http://getcomposer.org/.

  1. Run composer require resque/php-resque.

  2. If you haven't already, add the Composer autoload to your project's initialization file. (example)

require 'vendor/autoload.php';

Jobs

Queueing Jobs

Jobs are queued as follows:

// Required if redis is located elsewhere
Resque\Resque::setBackend('localhost:6379');

$args = array(
          'name' => 'Chris'
        );
Resque\Resque::enqueue('default', 'My_Job', $args);

Defining Jobs

Each job should be in its own class, and include a perform method.

class My_Job
{
    public function perform()
    {
        // Work work work
        echo $this->args['name'];
    }
}

When the job is run, the class will be instantiated and any arguments will be set as an array on the instantiated object, and are accessible via $this->args.

Any exception thrown by a job will result in the job failing - be careful here and make sure you handle the exceptions that shouldn't result in a job failing.

Jobs can also have setUp and tearDown methods. If a setUp method is defined, it will be called before the perform method is run. The tearDown method, if defined, will be called after the job finishes.

class My_Job
{
    public function setUp()
    {
        // ... Set up environment for this job
    }

    public function perform()
    {
        // .. Run job
    }

    public function tearDown()
    {
        // ... Remove environment for this job
    }
}

Dequeueing Jobs

This method can be used to conveniently remove a job from a queue.

// Removes job class 'My_Job' of queue 'default'
Resque\Resque::dequeue('default', ['My_Job']);

// Removes job class 'My_Job' with Job ID '087df5819a790ac666c9608e2234b21e' of queue 'default'
Resque\Resque::dequeue('default', ['My_Job' => '087df5819a790ac666c9608e2234b21e']);

// Removes job class 'My_Job' with arguments of queue 'default'
Resque\Resque::dequeue('default', ['My_Job' => array('foo' => 1, 'bar' => 2)]);

// Removes multiple jobs
Resque\Resque::dequeue('default', ['My_Job', 'My_Job2']);

If no jobs are given, this method will dequeue all jobs matching the provided queue.

// Removes all jobs of queue 'default'
Resque\Resque::dequeue('default');

Tracking Job Statuses

php-resque has the ability to perform basic status tracking of a queued job. The status information will allow you to check if a job is in the queue, is currently being run, has finished, or has failed.

To track the status of a job, pass true as the fourth argument to Resque\Resque::enqueue. A token used for tracking the job status will be returned:

$token = Resque\Resque::enqueue('default', 'My_Job', $args, true);
echo $token;

To fetch the status of a job:

$status = new Resque\Job\Status($token);
echo $status->get(); // Outputs the status

Job statuses are defined as constants in the Resque\Job\Status class. Valid statuses include:

  • Resque\Job\Status::STATUS_WAITING - Job is still queued
  • Resque\Job\Status::STATUS_RUNNING - Job is currently running
  • Resque\Job\Status::STATUS_FAILED - Job has failed
  • Resque\Job\Status::STATUS_COMPLETE - Job is complete
  • false - Failed to fetch the status; is the token valid?

Statuses are available for up to 24 hours after a job has completed or failed, and are then automatically expired. A status can also forcefully be expired by calling the stop() method on a status class.

Obtaining job PID

You can obtain the PID of the actual process doing the work through Resque\Job\PID. On a forking OS this will be the PID of the forked process.

CAUTION: on a non-forking OS, the PID returned will be of the worker itself.

echo Resque\Job\PID::get($token);

Function returns 0 if the perform hasn't started yet, or if it has already ended.

Delayed Jobs

To quote the documentation for the Ruby resque-scheduler:

Delayed jobs are one-off jobs that you want to be put into a queue at some point in the future. The classic example is sending an email:

require 'Resque.php';
require 'Scheduler.php';

$in = 3600;
$args = array('id' => $user->id);
Resque\Scheduler::enqueueIn($in, 'email', 'SendFollowUpEmail', $args);

The above will store the job for 1 hour in the delayed queue, and then pull the job off and submit it to the email queue in Resque for processing as soon as a worker is available.

Instead of passing a relative time in seconds, you can also supply a timestamp as either a DateTime object or integer containing a UNIX timestamp to the enqueueAt method:

require 'Resque.php';
require 'Scheduler.php';

$time = 1332067214;
Resque\Scheduler::enqueueAt($time, 'email', 'SendFollowUpEmail', $args);

$datetime = new DateTime('2012-03-18 13:21:49');
Resque\Scheduler::enqueueAt($datetime, 'email', 'SendFollowUpEmail', $args);

NOTE: resque-scheduler does not guarantee a job will fire at the time supplied. At the time supplied, resque-scheduler will take the job out of the delayed queue and push it to the appropriate queue in Resque. Your next available Resque worker will pick the job up. To keep processing as quick as possible, keep your queues as empty as possible.

Workers

Workers work in the exact same way as the Ruby workers. For complete documentation on workers, see the original documentation.

A basic "up-and-running" bin/resque file is included that sets up a running worker environment. (vendor/bin/resque when installed via Composer)

The exception to the similarities with the Ruby version of resque is how a worker is initially setup. To work under all environments, not having a single environment such as with Ruby, the PHP port makes no assumptions about your setup.

To start a worker, it's very similar to the Ruby version:

$ QUEUE=file_serve php bin/resque

It's your responsibility to tell the worker which file to include to get your application underway. You do so by setting the APP_INCLUDE environment variable:

$ QUEUE=file_serve APP_INCLUDE=../application/init.php php bin/resque

Pro tip: Using Composer? More than likely, you don't need to worry about APP_INCLUDE, because hopefully Composer is responsible for autoloading your application too!

Getting your application underway also includes telling the worker your job classes, by means of either an autoloader or including them.

Alternately, you can always include('bin/resque') from your application and skip setting APP_INCLUDE altogether. Just be sure the various environment variables are set (setenv) before you do.

Logging

The port supports the same environment variables for logging to STDOUT. Setting VERBOSE will print basic debugging information and VVERBOSE will print detailed information.

$ VERBOSE=1 QUEUE=file_serve bin/resque
$ VVERBOSE=1 QUEUE=file_serve bin/resque

Priorities and Queue Lists

Similarly, priority and queue list functionality works exactly the same as the Ruby workers. Multiple queues should be separated with a comma, and the order that they're supplied in is the order that they're checked in.

As per the original example:

$ QUEUE=file_serve,warm_cache bin/resque

The file_serve queue will always be checked for new jobs on each iteration before the warm_cache queue is checked.

Running All Queues

All queues are supported in the same manner and processed in alphabetical order:

$ QUEUE='*' bin/resque

Running Multiple Workers

Multiple workers can be launched simultaneously by supplying the COUNT environment variable:

$ COUNT=5 bin/resque

Be aware, however, that each worker is its own fork, and the original process will shut down as soon as it has spawned COUNT forks. If you need to keep track of your workers using an external application such as monit, you'll need to work around this limitation.

Custom prefix

When you have multiple apps using the same Redis database it is better to use a custom prefix to separate the Resque data:

$ PREFIX=my-app-name bin/resque

Setting Redis backend

When you have the Redis database on a different host than the one the workers are running, you must set the REDIS_BACKEND environment variable:

$ REDIS_BACKEND=my-redis-ip:my-redis-port bin/resque

Forking

Similarly to the Ruby versions, supported platforms will immediately fork after picking up a job. The forked child will exit as soon as the job finishes.

The difference with php-resque is that if a forked child does not exit nicely (PHP error or such), php-resque will automatically fail the job.

Signals

Signals also work on supported platforms exactly as in the Ruby version of Resque:

  • QUIT - Wait for job to finish processing then exit
  • TERM / INT - Immediately kill job then exit
  • USR1 - Immediately kill job but don't exit
  • USR2 - Pause worker, no new jobs will be processed
  • CONT - Resume worker.

Process Titles/Statuses

The Ruby version of Resque has a nifty feature whereby the process title of the worker is updated to indicate what the worker is doing, and any forked children also set their process title with the job being run. This helps identify running processes on the server and their resque status.

PHP does not have this functionality by default until 5.5.

A PECL module (http://pecl.php.net/package/proctitle) exists that adds this functionality to PHP before 5.5, so if you'd like process titles updated, install the PECL module as well. php-resque will automatically detect and use it.

Resque Scheduler

resque-scheduler requires a special worker that runs in the background. This worker is responsible for pulling items off the schedule/delayed queue and adding them to the queue for resque. This means that for delayed or scheduled jobs to be executed, that worker needs to be running.

A basic "up-and-running" bin/resque-scheduler file that sets up a running worker environment is included (vendor/bin/resque-scheduler when installed via composer). It accepts many of the same environment variables as the main workers for php-resque:

  • REDIS_BACKEND - Redis server to connect to
  • LOGGING - Enable logging to STDOUT
  • VERBOSE - Enable verbose logging
  • VVERBOSE - Enable very verbose logging
  • INTERVAL - Sleep for this long before checking scheduled/delayed queues
  • APP_INCLUDE - Include this file when starting (to launch your app)
  • PIDFILE - Write the PID of the worker out to this file

It's easy to start the resque-scheduler worker using bin/resque-scheduler: $ php bin/resque-scheduler

Event/Hook System

php-resque has a basic event system that can be used by your application to customize how some of the php-resque internals behave.

You listen in on events (as listed below) by registering with Resque\Event and supplying a callback that you would like triggered when the event is raised:

Resque\Event::listen('eventName', [callback]);

[callback] may be anything in PHP that is callable by call_user_func_array:

  • A string with the name of a function
  • An array containing an object and method to call
  • An array containing an object and a static method to call
  • A closure (PHP 5.3+)

Events may pass arguments (documented below), so your callback should accept these arguments.

You can stop listening to an event by calling Resque\Event::stopListening with the same arguments supplied to Resque\Event::listen.

It is up to your application to register event listeners. When enqueuing events in your application, it should be as easy as making sure php-resque is loaded and calling Resque\Event::listen.

When running workers, if you run workers via the default bin/resque script, your APP_INCLUDE script should initialize and register any listeners required for operation. If you have rolled your own worker manager, then it is again your responsibility to register listeners.

A sample plugin is included in the extras directory.

Events

beforeFirstFork

Called once, as a worker initializes. Argument passed is the instance of Resque\Worker\ResqueWorker that was just initialized.

beforeFork

Called before php-resque forks to run a job. Argument passed contains the instance of Resque\JobHandler for the job about to be run.

beforeFork is triggered in the parent process. Any changes made will be permanent for as long as the worker lives.

afterFork

Called after php-resque forks to run a job (but before the job is run). Argument passed contains the instance of Resque\JobHandler for the job about to be run.

afterFork is triggered in the child process after forking out to complete a job. Any changes made will only live as long as the job is being processed.

beforePerform

Called before the setUp and perform methods on a job are run. Argument passed contains the instance of Resque\JobHandler for the job about to be run.

You can prevent execution of the job by throwing an exception of Resque\Exceptions\DoNotPerformException. Any other exceptions thrown will be treated as if they were thrown in a job, causing the job to fail.

afterPerform

Called after the perform and tearDown methods on a job are run. Argument passed contains the instance of Resque\JobHandler that was just run.

Any exceptions thrown will be treated as if they were thrown in a job, causing the job to be marked as having failed.

onFailure

Called whenever a job fails. Arguments passed (in this order) include:

  • Exception - The exception that was thrown when the job failed
  • Resque\JobHandler - The job that failed

beforeEnqueue

Called immediately before a job is enqueued using the Resque\Resque::enqueue method. Arguments passed (in this order) include:

  • Class - string containing the name of the job to be enqueued
  • Arguments - array of arguments for the job
  • Queue - string containing the name of the queue the job is to be enqueued in
  • ID - string containing the token of the job to be enqueued

You can prevent enqueing of the job by throwing an exception of Resque\Exceptions\DoNotCreateException.

afterEnqueue

Called after a job has been queued using the Resque\Resque::enqueue method. Arguments passed (in this order) include:

  • Class - string containing the name of scheduled job
  • Arguments - array of arguments supplied to the job
  • Queue - string containing the name of the queue the job was added to
  • ID - string containing the new token of the enqueued job

afterSchedule

Called after a job has been added to the schedule. Arguments passed are the timestamp, queue of the job, the class name of the job, and the job's arguments.

beforeDelayedEnqueue

Called immediately after a job has been pulled off the delayed queue and right before the job is added to the queue in resque. Arguments passed are the queue of the job, the class name of the job, and the job's arguments.

Step-By-Step

For a more in-depth look at what php-resque does under the hood (without needing to directly examine the code), have a look at HOWITWORKS.md.

Contributors

Project Creator

  • @chrisboulton

Project Maintainers

  • @danhunsaker
  • @rajibahmed
  • @steveklabnik

Others

  • @acinader
  • @ajbonner
  • @andrewjshults
  • @atorres757
  • @benjisg
  • @biinari
  • @cballou
  • @chaitanyakuber
  • @charly22
  • @CyrilMazur
  • @d11wtq
  • @dceballos
  • @ebernhardson
  • @hlegius
  • @hobodave
  • @humancopy
  • @iskandar
  • @JesseObrien
  • @jjfrey
  • @jmathai
  • @joshhawthorne
  • @KevBurnsJr
  • @lboynton
  • @maetl
  • @matteosister
  • @MattHeath
  • @mickhrmweb
  • @Olden
  • @patrickbajao
  • @pedroarnal
  • @ptrofimov
  • @rayward
  • @richardkmiller
  • @Rockstar04
  • @ruudk
  • @salimane
  • @scragg0x
  • @scraton
  • @thedotedge
  • @tonypiper
  • @trimbletodd
  • @warezthebeef

php-resque's People

Contributors

bc-vincent-zhao avatar cballou avatar chrisboulton avatar danhunsaker avatar drahmel avatar ebernhardson avatar hikariii avatar hobodave avatar humancopy avatar jaswdr avatar johnpremkumar avatar joycebabu avatar kevburnsjr avatar lauripiisang avatar lboynton avatar luishdez avatar maetl avatar mfn avatar mickhrmweb avatar patromo avatar pedroarnal avatar pprkut avatar rayward avatar richardkmiller avatar robholmes avatar rockstar04 avatar ruudk avatar theaxel avatar warezthebeef avatar wedy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-resque's Issues

Job Reservers

Expected Behavior

Refactor the current job reservation logic to call out to one of several, separate job reserver classes, and implement an additional one for selecting between configured queues at random.

Current Behavior

At the moment, only two reservation options exist - queue list iteration, or blocking pop. In the first, the worker scans each queue in order, and the first one it finds a job in is the one it pulls work from; it then restarts at the top of the list. In the second, the worker waits for any queue to have a job, but will still execute jobs in highest priority queues exclusively, until said queues are empty, before moving on to lower-priority queues. This isn't effective for all users, so an additional mechanism has been proposed, which checks queues in a random order, rather than in the configured "priority" order. To implement this effectively, it's helpful to pull the job reservation logic out into separate classes entirely, making the process of adding others considerably simpler in the future.

Possible Solution

The original attempt at this, by @rayward, was in chrisboulton/php-resque#338

Context

This feature was originally suggested and Pull Requested under the old home for this project. This issue is intended to pull this functionality over to the current repository.

Patch release

Can you release a minor patch release with the PHP 8.1 fixes?

QUEUE=message php vendor/bin/resque

Hi,all
in command line ,I run QUEUE=message php vendor/bin/resque;then I push many task into queue .but only one queue was execute.others also in queue.not execute.
anyone can help me ?

os: darwin Kernel Version 18.2.0

ask

hii, how to use this library in codeigniter 4 ?

PHP 7.2 to 7.4 compatibility ?

Does PHP Resque works on PHP 7.2, 7.3 and 7.4 ?

We are upgrading an old PHP 5 app, which using the original version of PHP Resque, and we need to know if we can keep using it with recent versions of PHP.

Could you update the Travis config so we can see the tests results ?

Woohoo!

Not an issue... just super excited to see migration progress begin, and looking forward to migrating our apps to use the new codebase. Thank you Dan!

Add support of Alpine based environment

In general, Alpine contains the ps command but not supports the -p option.
More detailed info can be found here - wodby/php#130

Expected Behavior

The managing of the child processes should just work.

Current Behavior

Currently each child process of the worker "freeze" after performing.

Possible Solution

Use PHP context to figure out if a child process exists in the returned list of the processes from executing ps -o command.

Context

Some of the provided docker php images do not contain the version of the ps command which compatible with the one used in the php-resque library.

Running under Docker in Kubernetes environment

Hi, I'd like to know if others are having success running php-resque in docker containers in a kubernetes environment.

I can share dockerfile/startup script if anyone is interested although its pretty standard.

One thing I cant get past is only 1 worker per container... this "makes sense" from a docker perspective but makes the workers more resource hungry than "legacy" workers...

I also notice that after a long time some job queues consistently fail with dirty 255 exceptions. I believe these are jobs erroring due to oom errors, but I havent been able to pinpoint it 100%... I know this specific queue is resource intensive (esp cpu hungry on "traditional" workers).

The main idea for this issue is to share experiences and best practices... Currently looking for an elegant way to restart the queue runner every X time or X processes, or something.

in demo of resque is not working . it is not picking class name

getting class not found error

[notice] Starting work on (Job{default} | ID: f8c29eab8d18d1a3933d0284eee95145 | My_Job | [{"name":"Chris"}])
[critical] (Job{default} | ID: f8c29eab8d18d1a3933d0284eee95145 | My_Job | [{"name":"Chris"}]) has failed Resque_Exception: Could not find job class My_Job. in /var/www/php-resque/lib/Resque/Job/Factory.php:17
Stack trace:
#0 /var/www/php-resque/lib/Resque/Job.php(172): Resque_Job_Factory->create('My_Job', Array, 'default')
#1 /var/www/php-resque/lib/Resque/Job.php(189): Resque_Job->getInstance()
#2 /var/www/php-resque/lib/Resque/Worker.php(255): Resque_Job->perform()
#3 /var/www/php-resque/lib/Resque/Worker.php(207): Resque_Worker->perform(Object(Resque_Job))
#4 /var/www/php-resque/bin/resque(185): Resque_Worker->work(5, false)
#5 {main}

my job class file

<?php
class My_Job
{
    public function setUp()
    {
      Resque::setBackend('localhost:6379'); 
    }

    public function perform()
    {
        file_put_contents("/var/www/php-resque/demo/mytxt1.txt",'tesddsadasdst');
         // file_put_contents("mytxt.txt",'test');

    }

    public function tearDown()
    {
        // ... Remove environment for this job
    }
}
  • PHP-Resque version:
  • PHP version: 7
  • Redis version:
  • Server type and version:
  • Operating System and version:

[redis 6] Authenticate with userpass from ACL

Redis 6 introduced userpass authentication with ACLs, which is used with managed Redis services offered by e.g. DigitalOcean. Though, I cannot authenticate workers because the username is not used for authentication:

// $user is not used, only $password

Expected Behavior

phpredis supports a variety of data structures to authenticate with a username and password, so I expected the username from my DSN connection string would be used:

list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server);

Current Behavior

if ($password){
$this->driver->auth($password);
}

Possible Solution

I put together the necessary patches for colinmollenhour/credis to test a very crude implementation, which I have on a fork here (please don't mind the whitespace 😅):

develop...kodumbeats:tls_connections

Context

Trying to hook up Appwrite to a Managed Redis database cluster provided by DigitalOcean but cannot due to this limitation.

Error systax when run on php 8.2

Using ${var} in strings is deprecated, use {$var} instead

Expected Behavior

I got error when run code on php 8.2, it relate to syntax of php 8.2
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /app/vendor/resque/php-resque/lib/Resque/Job/Status.php on line 48
Please update syntax in file Status.php, thank you.

Current Behavior

Possible Solution

Steps to Reproduce

Context

My Environment

  • PHP-Resque version: branch develop
  • PHP version: 8.2
  • Redis version:
  • Server type and version:
  • Operating System and version:

Suggestion: PSR-4 compliant namespace

It would be nice if the project moved to a PSR-4 compliant namespace. Since this would be a BC breaking change, this would require a major version bump.

resque-scheduler'title can not set to user'title,but resque-worker do

I compare the code between resque and resque-scheduler ,find thair differrency,

resque scheduler
private function updateProcLine($status)
{
$processTitle = 'resque-scheduler-' . ResqueScheduler::VERSION . ': ' . $status;
if(function_exists('setproctitle')) {
setproctitle($processTitle);
}

	echo "setproctitle = " .  function_exists('setproctitle') ? "true" : "false" . PHP_EOL;
}

resque worker
private function updateProcLine($status)
{
$processTitle = static::$processPrefix . '-' . Resque::VERSION . ' (' . implode(',', $this->queues) . '): ' . $status;
if(function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') {
cli_set_process_title($processTitle);
}
else if(function_exists('setproctitle')) {
setproctitle($processTitle);
}
}

Expected Behavior

Current Behavior

Possible Solution

Steps to Reproduce

Context

My Environment

  • PHP-Resque version:
  • PHP version:
  • Redis version:
  • Server type and version:
  • Operating System and version:

How do I programmatically start a worker

My question:

Hi. I wrote a wrapper for resque so I can initialize my environment before starting resque worker. According to docs, worker is triggered from vendor/bin/resque, which means I need to include, ostensibly, by cd-ing there. Is there some less hacky way recommended to go about this? Consumers of my wrapper may set bin folder to something else that will make it unreliable to hardcode

I just need to programmatically start the worker

My Environment

  • PHP-Resque version:
  • PHP version:
  • Redis version:
  • Server type and version:
  • Operating System and version:

My job could not find?

example:

    $data = [
        'class_name' => OrderService::class,
        'method_name' => 'defaultUserOrderData',
        'data' => 'user_order_data_1'
    ];
    $res = \Resque::enqueue('default', OrderJob::class, $data);

OrderJob::class is my job class.

error message:

"exception":"Resque_Exception","error":"Could not find job class Common\Job\OrderJob.","backtrace":["#0 /vagrant/project_yaoyaoduo_b2b/vendor/resque/php-resque/lib/Resque/Job.php(172): Resque_Job_Factory->create('Common\\Job\\Orde...', Array, 'default')", ....

Redis password extracted from DSN are not url-decoded

Expected Behavior

The password extracted from a Redis DSN should be url-decoded.

Current Behavior

The password extracted from a Redis DSN is not url-decoded.

Possible Solution

Use urldecode() to decode the password before passing it to redis.

Steps to Reproduce

Try 1:

  1. Use a password which looks like this: abc@#!
  2. Try to pass it into \Resque::setBackend()
    \Resque::setBackend('redis://x:abc@#[email protected]:6379/1');
  3. It won't work. The parse_url() function used in Resque_Redis::parseDsn() does not recognize this as a correct URL.

Try 2:

  1. Same password as above but encoded before passing it to \Resque::setBackend()
    \Resque::setBackend('redis://x:abc%40%[email protected]:6379/1');
  2. It won't work. The encoded password are passed to the redis backend, resulting in an invalid password exception.

Context

Passwords can contain special characters like :@/. In URL these characters must be encoded.

My Environment

  • PHP-Resque version: v1.3.3
  • PHP version: 5.6.40
  • Redis version: 5.0.3
  • Server type and version:
  • Operating System and version: Arch GNU/Linux (linux 4.19.26)

Throwable PHP7

Expected Behavior

PHP7 needs to catch Throwable instead Exception

Current Behavior

try-catch don't catch Throwable instead Exception

Possible Solution

refactor all try-catch

My Environment

  • PHP-Resque version: latest
  • PHP version: 7.1
  • Operating System and version: Ubuntu 18.10

Job dependencies

Hello,

Does php-resque support job dependencies? I would basically like to carry out a task that involves jobs A, B, C, and D. B+C depend on A being done. And D depends on B+C being done.
Is this supported out of the box? I couldn't see anything in the documentation but maybe I'm missing it.

Thanks!

Resque scan parameters are not as expected

My question:

The return value of 'scan' in 'redis' is a cursor and an array,' scan 'in' resque 'is an array, What do you suggest
In the case of redis

127.0.0.1:6379[7]> scan 0 match worker:job:* count 100
1) "0"
2) 1) "worker:job:backend\\modules\\job\\resque:10"
    2) "worker:job:backend\\modules\\job\\resque:20"

In the case of php-resque

$resqueList = Resque::redis()->scan($cursor,'worker:job:*',"100");
return $resqueList;

The return values are as follows

[
"worker:job:backend\modules\job\resque:10",
"worker:job:backend\modules\job\resque:20"
]

My Environment

  • PHP-Resque version:
  • PHP version: 7.1.32
  • Redis version: 4.2.0
  • Server type and version:
  • Operating System and version:

Prefixes are not properly documented

Expected Behavior

I tried to use a prefix. So I defined it while running my workers, and then I tried to use the same prefix when enqueuing.

Current Behavior

But it did not work, because the $prefix argument of this function is not the same thing.

Possible Solution

Document Resque_Redis::prefix in this part https://github.com/resque/php-resque#custom-prefix

Suggestion

If these two prefixes are not the same thing, I suggest to rename one. In another library, what you call "prefix" is called "namespace".

Cannot print every log row with time

Hi, when I use VERBOSE=1 it allows me get time only in
[notice] [22:30:35 2022-08-08] Starting worker ......
but I need to get it also in following lines of loger:
[notice] (Job{stats} | ID: xxxxxxxxxxxxxx | CampaignStatsJob etc.

How can I do this?

Any chance of bringing over the port of php-resque-scheduler?

Dont mean to hog the issues, nor to be pushy lol... But would it be fair to suggest to bring over php-resque-scheduler into this repo as well?

We use it in production, and even if it isnt maintained, the composer package requires chrisboulton/php-resque... Before I go trying to hack around I thought I'd ask?

I assume some others may be in a similar position too... Thanks for bringing this over! I hope we can contribute too in due time!

1.3.6 tag is not marked as a release

My question:

Could you create a release in GitHub for 1.3.6? Other versions are marked as a release.

My Environment

  • PHP-Resque version: 1.3.5
  • PHP version: 7.4
  • Redis version: N/A
  • Server type and version: N/A
  • Operating System and version: macOS 11.1

php 8.2.9 Creation of dynamic property deprecation notices

Expected Behavior

No deprecation notices

Current Behavior

PHP outputs deprecation notices due to undefined class properties that are later assigned.

PHP Deprecated:  Creation of dynamic property Resque_Worker::$logLevel is deprecated in 
...phplib\vendor\resque\php-resque\bin\resque on line 173

	$worker->logLevel = $logLevel;


PHP Deprecated:  Creation of dynamic property Resque_Redis::$driver is deprecated in 
...phplib\vendor\resque\php-resque\lib\Resque\Redis.php on line 134

	$this->driver = new Credis_Client($host, $port, $timeout, $persistent);


and probably elsewhere.

Possible Solution

declare the class properties, eg:

class Resque_Worker {
 ... 
 public $logLevel
}
class Resque_Redis
{
 ...
    private $driver;    // unsure what visibility is actually needed

}

Context

In this instance I am setting up a worker script that includes vendor/bin/resque, eg:

require __DIR__."/config.php";
require __DIR__ . '/../phplib/vendor/bin/resque';

My Environment

This should happen regardless of environment

  • PHP-Resque version: "resque/php-resque": "^1.3"
  • PHP version: 8.2.9
  • Redis version: 7.2
  • Server type and version: php internal web server / phpstorm
  • Operating System and version: windows 11

FastCGI (Job Strategies)

Expected Behavior

Refactor the current implementation to pull forking and in-process (no-fork) execution strategies into separate classes, which the worker processes will then use to actually spawn jobs according to sysadmin configuration. Then, add support for a FastCGI strategy, in addition to the forking and in-process strategies currently supported.

Current Behavior

Currently, only forking and in-process (non-forking) strategies are supported, and forking is used if it is supported, regardless of sysadmin preferences. This feature would allow the addition of other mechanisms under the hood, and give control over which to use to the sysadmin.

Possible Solution

The original attempt at this, by @ebernhardson, was in chrisboulton/php-resque#81

Context

This feature was originally suggested and Pull Requested under the old home for this project. This issue is intended to pull this functionality over to the current repository.

Queuing a closure

My question:

I'm facing prob with queuing closure, have you an idea how to do it?

My Environment

  • PHP-Resque version: v1.3.3
  • PHP version: PHP 7.2.20-1+ubuntu16.04.1+deb.sury.org+1
  • Redis version: 5.0.5 (dockerized)
  • Server type and version: I don't know.
  • Operating System and version: ubuntu

Events beforePerform, afterPerform not working?

Example of code:

function func10()
{
	_echo('before');
}

function func20()
{
	_echo('after');
}

	
#
Resque::setBackend('localhost:6379');

#
Resque_Event::listen('beforePerform','func10');
Resque_Event::listen('afterPerform' ,'func20');

#
Resque::enqueue('default','worker',[]);
  • PHP-Resque version: 1.3.6
  • PHP version: PHP 7.2.24
  • Redis version: 5.0.9
  • Operating System and version: Ubuntu 18.04.4

What could empty the Redis database (clear all keys)?

This questions concerns the basic Redis structure and how Resque operates on that, since I am not able to find out how this is dealt with. I am not familiar with Resque, but know how to work with Redis using the redis-cli.

My question:

We have a very low traffic Resque job queue (typically a few jobs a day) on a system not set up by me, with no monitoring whatsoever, and yesterday I was told no emails were being sent out. The Symfony logs were empty and I had nothing to go by, so I logged into the instance running Redis and found NOTHING. Doing KEYS * returned nil. That was scary, as I thought that even no jobs would at least list a few resque keys? Like resque:stat:failed, resque:workers, resque:queues, resque:stat:processed, resque:failed and so forth.

I then found the /data/dump.rdb file and ran strings on it: https://gist.github.com/fatso83/91e6b9ea0c977cabe949574bce08b778

From what I know, this is supposed to contain a persisted dump of what is in-mem and this dump was definitely NOT empty. It contained lots of interesting strings (see the link above to the redacted output).

Is it normal to have no keys in a working Resque Redis database or is this a sign of something going very wrong? Should I try restoring it or what do I do here?

My Environment

  • PHP-Resque version: "chrisboulton/php-resque": "dev-master" (yes, super old, but the disk layout should not have changed, right?)
  • PHP version: 7.4
  • Redis version: 3
  • Server type and version: AWS ECS instance, Docker container
  • Operating System and version: Linux

InvalidArgumentException when installing through composer

My question:

I'm having an issue while installing php-resque on a machine through composer. The only error message that is thrown is:

[InvalidArgumentException]                                                                  
  $from (/path/to/my/project/vendor/bin/resque) and $to () must be absolute paths.

Also, if I remove resque/php-resque from composer.json, all the other dependecies are correctly installed.

My Environment

  • PHP-Resque version: 1.3.3
  • PHP version: 5.5.9-1ubuntu4.29 (cli) (built: Apr 22 2019 18:33:52)
  • Composer version: 1.8.5 2019-04-09 17:46:47
  • Operating System and version: Ubuntu 14.04.6 LTS

Define goals/roadmap

I think it would help to community to get some idea where this would be going.

The codebase has a good and strong history, OTOH it also references software which is also very old (see composer.json: PHP 5.3, PHPUnit 3.* but not the PHP version isn't covered in travis for example.

What are some plans/ideas regarding:

  • Codestyle
  • Namespaces
  • PHP Support (7.0 is EOL)
  • Features (scheduler? plugins?)
  • resque-compatibility

Message: Undefined index: prefix in Job.php

i used version is "resque/php-resque": "v1.3.4"

A PHP Error was encountered

Severity: Notice
Message: Undefined index: prefix
Filename: Resque/vendor/resque/php-resque/lib/Resque/Job.php
Line Number: 145

Expected Behavior

i don't know how to set prefix to my jobs

thanks

My Environment

  • PHP-Resque version: v1.3.4
  • PHP version: 7.2
  • Redis version: 3.0.7
  • Server type and version:
  • Operating System and version:

Possibility of multiple concurrent workers fetching same job

My question:

Is there a possibility of fetching and processing same job while multiple concurrent workers are in place?

My Environment

  • PHP-Resque version:
  • PHP version:
  • Redis version:
  • Server type and version:
  • Operating System and version:

Arguments have other encodings than utf-8

Jobs don't get queued when arguments have invalid (non utf-8) encoding. Also you get a valid ID.

Expected Behavior

\Resque::enqueue() should fail with a meaningful error message

Current Behavior

\Resque::enqueue() returns with a valid ID but there is no job in the Redis-DB.

Possible Solution

Throw an exception, when json_encode in Resque::push() fails and check return value when Resque::push() gets called in Job::create()

Steps to Reproduce

    Resque::enqueue('jobs', 'Test_Job', [
        'myStr' => utf8_decode('Düsseldorf'),
    ])

My Environment

  • PHP-Resque version: 1.3
  • PHP version: 7.2.24
  • Redis version: 2:3.0.6-1ubuntu0.4
  • Server type and version: php-cli
  • Operating System and version: 2:3.0.6-1ubuntu0.4

redis have a password

My question:

hey when I try to run the worker, how do I get it to get the redis configuration, because my redis have a password.

QUEUE='*' vendor/bin/resque

PHP Fatal error: Uncaught CredisException: NOAUTH Authentication required. in

My Environment

  • PHP-Resque version:
  • PHP version:7.4
  • Redis version:
  • Server type and version:
  • Operating System and version:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.