Code Monkey home page Code Monkey logo

php-resque-scheduler's Introduction

php-resque-scheduler: PHP Resque Scheduler

php-resque-scheduler is a PHP port of resque-scheduler, which adds support for scheduling items in the future to Resque.

The PHP port of resque-scheduler has been designed to be an almost direct-copy of the Ruby plugin, and is designed to work with the PHP port of resque, php-resque.

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.

Because the PHP port is almost a direct API copy of the Ruby version, it is also compatible with the web interface of the Ruby version, which provides the ability to view and manage delayed jobs.

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/Resque.php';
require 'ResqueScheduler/ResqueScheduler.php';

$in = 3600;
$args = array('id' => $user->id);
ResqueScheduler::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/Resque.php';
require 'ResqueScheduler/ResqueScheduler.php';

$time = 1332067214;
ResqueScheduler::enqueueAt($time, 'email', 'SendFollowUpEmail', $args);

$datetime = new DateTime('2012-03-18 13:21:49');
ResqueScheduler::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.

Worker

Like resque, resque-scheduler includes a 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, the worker needs to be running.

A basic "up-and-running" resque-scheduler.php file is included that sets up a running worker environment is included in the root directory. It accepts many of the same environment variables as 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

The resque-scheduler worker requires resque to function. The demo resque-scheduler.php worker allows you to supply a RESQUE_PHP environment variable with the path to Resque.php. If not supplied and resque is not already loaded, resque-scheduler will attempt to load it from your include path (require_once 'Resque/Resque.php';')

It's easy to start the resque-scheduler worker using resque-scheduler.php: $ RESQUE_PHP=../resque/lib/Resque/Resque.php php resque-scheduler.php

Event/Hook System

php-resque-scheduler uses the same event system used by php-resque and exposes the following events.

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.

Contributors

  • chrisboulton
  • rayward
  • atorres757
  • tonypiper
  • biinari
  • cballou

php-resque-scheduler's People

Contributors

biinari avatar cballou avatar chrisboulton avatar danhunsaker avatar jaaprood avatar mhagstrand avatar rayward avatar robholmes avatar smalot avatar spekulatius avatar tonypiper 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

php-resque-scheduler's Issues

new stable release

Hi,

Is it possible to get new stable release in the near future?

Best regards,
Michal

Tagging releases

Ever heard of tagging releases? It’s really handy, it allows you to mark a given commit as stable, which allows people to use the software without requiring dev-master and suffer from the weathercock behaviour of some contributors, like this:

f1a5596 Fixing zrangebyscore. (which is in fact breaking it)
37ea2e2 Removing unneeded fix in last commit.
110e213 Revert "Removing unneeded fix in last commit." (which was a really stupid thing to do)

Today I’m hit with chrisboulton/php-resque#50 and I can’t fix it because I should switch php-resque to dev-master, which requires me to use php-resque-scheduler in dev-master, which is broken because of the above example.

What queue to poll?

Hi,

I have been using php-resque with large success, but I am having a hard time understanding the scheduler.
When I run the resque-scheduler.php example, it asks which queue to poll. I imagine it is asking for the name of the delayed queue, and after peeking thru the code, I guessed that the queue is called: delayed_queue_schedule

Is this correct?

Add support for dynamically changing the schedule (match functionality of Resque 2.x)

From the Resque README, they now support dynamically changing the schedule:

# If you want to be able to dynamically change the schedule,
# uncomment this line.  A dynamic schedule can be updated via the
# Resque::Scheduler.set_schedule (and remove_schedule) methods.
# When dynamic is set to true, the scheduler process looks for
# schedule changes and applies them on the fly.
# Note: This feature is only available in >=2.0.0.
#Resque::Scheduler.dynamic = true

https://github.com/bvandenbos/resque-scheduler

Example code

I tried the example code but its not completed? At least the require path is not correct.

I was able to edit to something like this

require 'lib/Resque.php';
require 'php-resque-scheduler/lib/ResqueScheduler.php';

$in = 3600;
$args = array('id' => "myemail");
ResqueScheduler::enqueueIn($in, 'email', 'SendFollowUpEmail', $args);

However when I run this, I dont see the job is listed on resque-web at http://localhost:5678/ so I assume the code does not work?

Project Cleanup

I won't argue that this project has fallen to the wayside a bit , but I--for one--would like to help.

I see that people are watching this repo and would care to make some improvements.

Things that I see that need some help:

  • #21 has a few good fixes, especially when it comes to running the service (and updating the corresponding docs) in a way that makes a lot more sense as it brings it in line with php-resque and how to start that service. However, it seems as though anyone with access to this repo (Cc @chrisboulton) haven't commented or merged or anything with that aging Pull Request. This fork however, is a good place to start.
  • A major feature missing from this repo is a way to stop a scheduled before it happens. At least, it doesn't seem to be documented, and I went looking for it a bit in the code and saw no efforts to that end. We could use a token system similar to the one in php-resque and use that token to stop tasks that haven't yet started.
  • There indeed is something fishy with all the zrangebyscore stuff (f1a5596, 37ea2e2, 110e213), and we need to get to the bottom of this and fix it for good.
  • There is some confusion to the tagging system and how it relates to php-resque and this needs to be figured out.
  • Tests would help out a lot with most of these issues and protecting ourselves from reverting any issues we might have fixed once before.

I saw "we," because I am willing to help out, but without someone to merge (and there is currently no evidence that there will be), it will all be in vain. Someone can step up and create and offer to maintain a fork, but with the tight relationship that this project has with the much more popular php-resque, that may be a hard sell. But I am at least willing to volunteer to do what I can to address the list above.

Or we can move on and find a better project. Indeed, what are some good alternatives when it comes to a PHP task scheduler and queuing system?

'monit stop all' doesn't actually kill the php-resque-scheduler worker

We use the exact stop command provided with php-resque-scheduler:

stop program = "/bin/sh -c 'kill -s QUIT cat /var/run/resque/scheduler-worker.pid && rm -f /var/run/resque/scheduler-worker.pid; exit 0;'"

We found that the pid file was removed, but the scheduler worker wasn't killed. What would be the root cause of that? Could we use kill -9 if kill -s QUIT doesn't work?

Add support for dynamically changing the schedule (match functionality of Resque 2.x)

From the Resque README, they now support dynamically changing the schedule:

# If you want to be able to dynamically change the schedule,
# uncomment this line.  A dynamic schedule can be updated via the
# Resque::Scheduler.set_schedule (and remove_schedule) methods.
# When dynamic is set to true, the scheduler process looks for
# schedule changes and applies them on the fly.
# Note: This feature is only available in >=2.0.0.
#Resque::Scheduler.dynamic = true

https://github.com/bvandenbos/resque-scheduler

Ability to set Credis_Client retry max

On AWS the network is less than perfect.
I'm planning on forking this and adding a way to increase the retry limit. We have our workers go down pretty often when amazon gets nasty.

I'll do a pull request in case anyone else has this issue. I'm going to set it up to pass in with environment variables. Hopefully I'm not duplicating work, but I didn't see any way to accomplish this from the CLI.

Error viewing job with namespace in resque-web

I appreciate this may be an issue with resque-web rather than this package but I wanted to check first if anyone could recreate it...

When I submit a job to be delayed it correctly adds it to redis as I'd expect however when I log into resque web and click the "delayed" tab I get an error:

URI::InvalidURIError at /delayed bad URI(is not URI?): /delayed/jobs/Namespace\Of\Job\Class?args=[%7B%....

It looks to me like an issue with the namespace of the job not being urlsafe...

Has anyone experienced this / resolved it?

p.s amazing work on this suite of packages! I couldn't live without php-resque!

`ResqueScheduler::removeDelayed` does not work on version 1.1

ResqueScheduler::removeDelayed calls removePrefix on line 115. However, in php-resque-scheduler version 1.1 the php-resque dependency is at version 1.2, where removePrefix does not exist yet, and the removePrefix call fails silently, returning just false. I assume the silent failure is caused by dynamic calls to Redis wrappers (or Redis itself).

Upgrading to dev-master fixed the problem.

I guess this bug isn't really worth a new release, though it'd be nice if the issue was left open for other people to notice until a new tagged version of php-resque-scheduler appeared. I'm not too keen on depending on dev-master. :)

Recurring/Scheduled/"Cron-like" Tasks

The README states that only the at-like functionality is implemented, and the cron-like functionality is planned for a future release. Upon investigation of how resque-scheduler works, it seems to rely on an external library to actually act as the cron portion, which then merely schedules tasks using the at-like functionality actually built in.

So my question - and this issue is more of a discussion starter than a bug report - is whether we want to implement this functionality in this manner, or if we wish to take a different approach that leverages the fact we're using Redis already anyway. I have an idea that I'd like to flesh out a bit before I propose it more formally, but I was curious if there were any other opinions already out there.

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.