Git Product home page Git Product logo

mage-resque's Introduction

Mage Resque

Mage Resque is a lightweight Magento implementation of the PHP Resque library and job runner. PHP Resque itself is based on Ruby's Resque, a Redis backed background job processing library.

Getting started

Licence

Mage Resque is covered by the MIT opensource licence. Unless specifically stated otherwise, terms of use are as laid out in the included LICENCE file.

Requirements

  • PHP 7.2+
  • Redis 2.2+
  • ext-pcntl
  • Magento 1.9.3.9+
  • Composer

Installation

Mage Resque uses Composer and Magento Composer Installer to handle installation of the module and its dependencies. To install Mage Resque you will need a copy of composer.phar in your path. If you do not have it availble, run the following commands from your terminal.

$ curl -sS https://getcomposer.org/installer | php
$ chmod a+x composer.phar

If you are already using Magento Composer Installer and have an existing composer.json, add https://github.com/ajbonner/mage-resque to the repositories list and ajbonner/mage-resque as a required dependency for your project. That's it!

If you do not have an existing Magento Composer Installer composer.json file defined, you can use the following template.

{
    "require": {
        "ajbonner/mage-resque": "*"
    },
    "require-dev": {
        "fbrnc/Aoe_Profiler": "*",
        "MageTest/Mage-Test": "*"
    },
    "repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/magento-hackathon/magento-composer-installer"
    },
    {
        "type": "vcs",
        "url": "https://github.com/ajbonner/magento-composer-autoload"
    },
    {
        "type": "vcs",
        "url": "https://github.com/ajbonner/mage-resque"
    },
    {
        "type": "vcs",
        "url": "https://github.com/MageTest/Mage-Test"
    },
    {
        "type": "vcs",
        "url": "https://github.com/fbrnc/Aoe_Profiler"
    }
    ],
    "extra":{
        "magento-root-dir": "./"
    },
    "config": {
        "bin-dir": "shell"
    },
    "minimum-stability": "dev"
}

To install Mage Resque and its dependencies just run composer.phar.

$ ./composer.phar install

Configuration

PHP Resque is a Redis backed job queue, and you will need access to a running Redis instance. To use a particular Redis server and database, add the following xml snippet to local.xml.

<!-- This is a child node of config for Magento CE -->
<default>
    <mnsresque>
        <redis>
            <backend>localhost:6379</backend>
            <database>1</database>
        </redis>
    </mnsresque>
</default>

If you use Redis for Magento caching or as a session store, e.g. you use one of Colin Mollenhour's excellent modules, then make sure you select an alternate database, or better yet, a separate Redis instance that is exclusively for Mage Resque.

If you are storing your binaries in a different directory, you can specify it in local.xml as well:

<default>
    <mnsresque>
       ...
       <env>
         <bin_dir>bin</bin_dir>
       </env>
    </mnsresque>
</default>

You can configure the number of resque workers to start by adding a <num_workers/> element to your mnsresque env configuation:

<default>
    <mnsresque>
       ...
       <env>
         ...
         <num_workers>4</num_workers>
       </env>
    </mnsresque>
</default>

All configuration options can be found in app/code/community/ajbonner/mage-resque/etc/config.xml in the defaults section.

Usage

PHP Resque has two functions, to add jobs to Redis backed job queues, and to manage workers processing jobs from those queues.

As an example, let's add a simple job to a queue that writes a message to Magento's system log. Mage Resque bundles Mns_Resque_Model_Job_Logmessage to do just this.

$resque = Mage::getSingleton('mnsresque/factory')->create();
$resque->addJob(
	'Mns_Resque_Model_Job_Logmessage',
	array('message'=>'foo'));

You can pass any classname to addJob that identifies a class implementing a process() method. You can find out more about how Job classes work in the PHP Redis README.

To process the queue and run background jobs, Mage Resque provides a job runner in the shell directory. To start it run the following command from your terminal.

$ php shell/resque.php --daemon

To stop the daemon gracefully (allow workers to finish their current job) run the following command.

$ php shell/resque.php --quit

To stop the daemon immediately (which means stopping workers potentially in the middle of a job) use the --terminate option.

$ php shell/resque.php --terminate

Running Unit Tests

Mage Resque comes bundled with a UnitTest Suite. This suite serves as a regression safety net and as rough documentation on the use of the module. To execute the tests you will need to install Mage Resque's development dependencies.

$ composer.phar install --dev

If you have ran composer.phar install, you will need to delete composer.lock and the vendor directory, then re-run install with the --dev argument.

To run the tests, in your Magento root directory, issue the following command from your terminal.

$ phpunit -c vendor/ajbonner/mage-resque/tests/phpunit.xml

Feedback and pull requests are very welcome. You can get in touch with me on twitter @ajbonner or via the issues system here on github.

mage-resque's People

Contributors

ajbonner avatar janpapenbrock avatar jasonevans1 avatar

Stargazers

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

Watchers

 avatar  avatar

mage-resque's Issues

Job Class not found

Hi ,

I have followed the instructions and installed the mage-resque. When i tested using Logmessage its returning following error.

[debug] [11:09:42 2016-03-27] Registered signals [info] [11:09:42 2016-03-27] Checking default for jobs [info] [11:09:42 2016-03-27] Found job on default [notice] [11:09:42 2016-03-27] Starting work on (Job{default} | ID: 6fe2a430c10ff2920c3f66ec7d52e957 | Mns_Resque_Model_Job_Logmessage | [{"message":"Resque Test 1459057136"}]) [info] [11:09:42 2016-03-27] Forked 3759 at 2016-03-27 11:09:42 [info] [11:09:42 2016-03-27] Processing default since 2016-03-27 11:09:42 [critical] [11:09:42 2016-03-27] (Job{default} | ID: 6fe2a430c10ff2920c3f66ec7d52e957 | Mns_Resque_Model_Job_Logmessage | [{"message":"Resque Test 1459057136"}]) has failed Could not find job class Mns_Resque_Model_Job_Logmessage.

I'm sure that i have missed something but couldn't figure out

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.