Giter VIP home page Giter VIP logo

cakephp-queue's Introduction

CakePHP Queue Plugin

CI Coverage Status Latest Stable Version Minimum PHP Version PHPStan License Total Downloads Coding Standards

This branch is for use with CakePHP 5.0+. For details see version map.

Background

This is a very simple and minimalistic job queue (or deferred-task) system for CakePHP. If you need a very basic PHP internal queue tool, this is definitely an option. It is also a great tool for demo purposes on how queues work and doesn't have any dependencies.

Overall functionality is inspired by systems like Gearman, Beanstalk or dropr, but without any illusion to compete with these more advanced Systems.

The plugin is an attempt to provide a basic, simple to use method to enable deferred job execution, without the hassle of setting up or running an extra queue daemon, while integrating nicely into CakePHP and also simplifying the creation of worker scripts. You can also easily provide progress and status information into your pages.

Please also read my blog posts about deferred execution and real-life example usage [new]. For more high-volume and sophisticated use cases please see the awesome list alternatives.

Why use deferred execution?

Deferred execution makes sense (especially in PHP) when your page wants to execute tasks, which are not directly related to rendering the current page. For instance, in a BBS-type system, a new users post might require the creation of multiple personalized email messages, notifying other users of the new content. Creating and sending these emails is completely irrelevant to the currently active user, and should not increase page response time. Another example would be downloading, extraction and/or analyzing an external file per request of the user. The regular solution to these problems would be to create specialized cronjobs which use specific database states to determine which action should be done.

The Queue plugin provides a simple method to create and run such non-user-interaction-critical tasks.

Another important reason is that specific jobs can be (auto)retried if they failed. So if the email server didn't work the first time, or the API gateway had an issue, the current job to be executed isn't lost but kept for rerun. Most of those external services should be treated as failable once every x calls, and as such a queue implementation can help reducing issues due to such failures. If a job still can't finish despite retries, you still have the option to debug its payload and why this job cannot complete. No data is lost here.

While you can run multiple workers, and can (to some extent) spread these workers to different machines via a shared database, you should consider using a more advanced system for high volume/high number of workers systems.

Demo

See Sandbox app.

Installation and Usage

See Documentation.

Cronjob based background scheduling

If you are looking for scheduling certain background jobs: This plugin works flawlessly with QueueScheduler plugin.

cakephp-queue's People

Contributors

challgren avatar charukiewicz avatar davidyell avatar deefuse avatar dereuromark avatar dmromanov avatar drmonkeyninja avatar fabian-mcfly avatar garas avatar graziel avatar houseoftech avatar inoas avatar jacobagtyler avatar jiru avatar julianpollmann avatar kburton-dev avatar kminek avatar lordsimal avatar luke83 avatar mfrascati avatar mseven avatar mstroink avatar netstyler avatar passchn avatar repher avatar ryanolton avatar spriz avatar stmeyer avatar suhaboncukcu avatar tecknix 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

cakephp-queue's Issues

Specified group not executed

I made some samples tasks in two groups. One group is Exemple (yours) and the other one is 'mytest'.

Only the group Exemple is executed when running runworker without parameter.
Running runworker with -g mytest doesn't run the mytest tasks.

Thanks

feature request

Is it possible to check if a task already exists before adding it again so its not fired off twice?

Doesnt work

Copying example doesn't work and it doesn't say what the name space should be. I get Task class Queue could not be found.

I copied QueueTask to my task folder and both classes use namespace App\Shell\Task;

Queue Task not mark as completed

Hi, I have problem with marking task as completed.

After command:
bin/cake Queue.Queue runworker
I have next message

Running Job of type MyType

MyTaskNameQueue task run.

Success

Job Finished.

But field "completed" set to NULL . Using your last version. CakePHP 3.2.14.
After some analysis, I found that the Entity does not change after patchEntity().
(here: /vendor/dereuromark/cakephp-queue/src/Model/Table/QueuedTasksTable.php):
public function markJobDone(QueuedTask $task) { $fields = [ 'completed' => date('Y-m-d H:i:s'), ]; $task = $this->patchEntity($task, $fields); return (bool)$this->save($task); }
Please tell me what I'm doing wrong ?

Initial migration doesn't work with Postgres

Hey guys, thanks for the great plugin.

I wasn't unable to create the required tables using Migrations as my app uses Postgres and your initial migration uses raw sql designed for mysql. Could you please fix your initial migration so it will be compatible with all supported db adapters? Should be something like this:

<?php

use Phinx\Migration\AbstractMigration;

class InitialMigration extends AbstractMigration {

    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     */
    public function change() {
        $table = $this->table('queued_tasks');
        $table->addColumn('jobtype', 'string', ['length' => 45])
            ->addColumn('data', 'text', ['null' => true])
            ->addColumn('group', 'string', ['length' => 255, 'null' => true, 'default' => null])
            ->addColumn('reference', 'string', ['length' => 255, 'null' => true, 'default' => null])
            ->addColumn('created', 'datetime', ['null' => true, 'default' => null])
            ->addColumn('notbefore', 'datetime', ['null' => true, 'default' => null])
            ->addColumn('fetched', 'datetime', ['null' => true, 'default' => null])
            ->addColumn('completed', 'datetime', ['null' => true, 'default' => null])
            ->addColumn('progress', 'float', ['null' => true])
            ->addColumn('failed', 'integer', ['default' => 0])
            ->addColumn('failure_message', 'text', ['null' => true])
            ->addColumn('workerkey', 'string', ['length' => 45, 'null' => true, 'default' => null])
            ->create();
    }
}

Many thanks.

How to use the clearDoublettes method?

I don't quite understand how to call the clearDoublettes method.
I want to build some kind of notification mailer for new entries in a forum.
When users send the same message to the board several times by mistake, other users shall only be notified once.

Would be great if someone could point me in the right direction.
I am using the 2.x branch for CakePHP 2.4

Tasks get schedules multiple times when multiple workers are running

Hi Mark,

I found a bug, but I don't quite know how to solve it. I'm seeing tasks rescheduled to quickly before timeout has passed. I nailed it down to this line:
Model/QueuedTask.php:154

The problem here is that you reference to $task which is part of the loop a few lines higher. This results in always the last element. Since I use your Plugin and plugins are parsed later the last (alphabetically) task's timeout wins. Which is always 10 seconds.

So, when 10 seconds are passed, the task is rescheduled when other un-finished tasks are also found. (Otherwise another if-statement catches it.)

Any ideas for fixes?

Greetings,

Rik

Unable to execute shell

Scenario
I have a shell which updates my database from a remote API. I want to run this shell at set points throughout the data and also be able to run it on user request.

Thought
I would use a queue system so that I could use a cron to add jobs to the queue at certain times of the day and also allow users to push jobs into the queue from the admin, proving there isn't a job within the last 30 minutes.

What I tried

// Controller
$this->QueuedTask->createJob('Execute', ['command' => 'Console/cake -app ~/Sites/BroadbandFinderCake/app api_updatable.update update ' . $model]);

Job data

INSERT INTO `queued_tasks` (`id`, `jobtype`, `data`, `group`, `reference`, `created`, `notbefore`, `fetched`, `completed`, `failed`, `failure_message`, `workerkey`)
VALUES
    (8, 'Execute', 'a:2:{s:7:\"command\";s:86:\"Console/cake -app ~/Sites/BroadbandFinderCake/app api_updatable.update update Provider\";s:6:\"params\";a:0:{}}', NULL, NULL, '2014-12-11 16:26:55', NULL, '2014-12-11 16:40:58', NULL, 2, NULL, 'd723282a3229dc11a206b0a8f34799625878eef6');

How did I test?

$ Console/cake queue.queue runworker

Result

Looking for Job....
Running Job of type "Execute"
Executing: Console/cake -app \~/Sites/BroadbandFinderCake/app api_updatable.update update Provider 
Error: Plugin ApiUpdatable could not be found.
#0 /Users/david/Sites/BroadbandFinderCake/Vendor/cakephp/cakephp/lib/Cake/Core/App.php(227): CakePlugin::path('ApiUpdatable')
#1 /Users/david/Sites/BroadbandFinderCake/Vendor/cakephp/cakephp/lib/Cake/Core/App.php(549): App::path('Console/Command', 'ApiUpdatable')
#2 [internal function]: App::load('UpdateShell')
#3 [internal function]: spl_autoload_call('UpdateShell')
#4 /Users/david/Sites/BroadbandFinderCake/Vendor/cakephp/cakephp/lib/Cake/Console/ShellDispatcher.php(249): class_exists('UpdateShell')
#5 /Users/david/Sites/BroadbandFinderCake/Vendor/cakephp/cakephp/lib/Cake/Console/ShellDispatcher.php(200): ShellDispatcher->_getShell('api_updatable.u...')
#6 /Users/david/Sites/BroadbandFinderCake/Vendor/cakephp/cakephp/lib/Cake/Console/ShellDispatcher.php(66): ShellDispatcher->dispatch()
#7 /Users/david/Sites/BroadbandFinderCake/app/Console/cake.php(38): ShellDispatcher::run(Array)
#8 {main}


Job did not finish, requeued.

How can I adjust the command that I am running to avoid

  • Having to pass the -app param
  • Preventing the prefix \

Read config values using Cake\Core\Configure

Instead of setting config values in app_queue.php in the config variable could we instead set config values using the conventional Cake\Core\Configure class, and do:
Configure::write(); in the boostrap.php?

Plugin localizations should have domains

Currently all of the localizations are using the format:
__('Localized string');
When using the plugin, all of the localizations are merged with the app localizations.

It would be better if localizations used the plugin domain ie.:
__d('cakephp-queue', 'Localized string');

Issue with creating execute Job from Controller.

Hi,
I am using this queue plugin to receive payloads from github via an http request and add some task.
I have written the controller as follows:

class ServicesController extends AppController {
    public function gitHooks(){
        $this->loadModel('Queue.QueuedTask');
        $this->QueuedTask->createJob('Execue', array('command'=>'git','params'=>array('checkout', 'origin', 'master', '-f')));
        exit;
    }
}

It adds the data to the queued_tasks table correctly but the worker doesn't recognise it and always says:
Looking for Job ...
nothing to do, sleeping.

Call to undefined method Cake\Mailer\Email::transportClass()

Hi,
When I use this plugin to Queue my Mail I get this error:

PHP Fatal error:  Call to undefined method Cake\Mailer\Email::transportClass() in /home/ian/PhpstormProjects/alumni/alumni/vendor/dereuromark/cakephp-queue/src/Shell/Task/QueueEmailTask.php on line 85
PHP Stack trace:
PHP   1. {main}() /home/ian/PhpstormProjects/alumni/alumni/bin/cake.php:0
PHP   2. Cake\Console\ShellDispatcher::run() /home/ian/PhpstormProjects/alumni/alumni/bin/cake.php:33
PHP   3. Cake\Console\ShellDispatcher->dispatch() /home/ian/PhpstormProjects/alumni/alumni/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php:127
PHP   4. Cake\Console\ShellDispatcher->_dispatch() /home/ian/PhpstormProjects/alumni/alumni/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php:181
PHP   5. Cake\Console\Shell->runCommand() /home/ian/PhpstormProjects/alumni/alumni/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php:217
PHP   6. call_user_func_array:{/home/ian/PhpstormProjects/alumni/alumni/vendor/cakephp/cakephp/src/Console/Shell.php:444}() /home/ian/PhpstormProjects/alumni/alumni/vendor/cakephp/cakephp/src/Console/Shell.php:444
PHP   7. Queue\Shell\QueueShell->runworker() /home/ian/PhpstormProjects/alumni/alumni/vendor/cakephp/cakephp/src/Console/Shell.php:444
PHP   8. Queue\Shell\Task\QueueEmailTask->run() /home/ian/PhpstormProjects/alumni/alumni/vendor/dereuromark/cakephp-queue/src/Shell/QueueShell.php:219

My settings are:

'EmailTransport' => [
        'default' => [
            'className' => 'Mail',
            // The following keys are used in SMTP transports
            'host' => 'localhost',
            'port' => 25,
            'timeout' => 30,
            'username' => 'user',
            'password' => 'secret',
            'client' => null,
            'tls' => null,
        ],
        'queue' => [
            'className' => 'Queue.Queue',
            'transport' => 'default'
        ]
    ],
'Email' => [
        'default' => [
            'transport' => 'queue',
            'from' => '[email protected]',
            'charset' => 'utf-8',
            'headerCharset' => 'utf-8',
        ]
    ],

Cakephp 3.2.5

worker not sending email while using Php mailer

public $default = array(
'transport' => 'Mail',
'from' => '[email protected]'
);

I am using above settings in my email config and using crontab
*/10 * * * * cd /var/www/html/beta/app/ && Console/cake Queue.Queue runworker > /tmp/queque.txt

cron tab runs every 10 minutes but email is not sending from php when i use some Smtp transport it start sending emails.

Note => when i run script manually using a web script
public function runJob(){

   echo exec('cd /var/www/html/beta/app/ && nohup Console/cake Queue.Queue runworker &');
   die('done');

}

it sends mail with Php transport but when it is started from crontab it goes to failure
what am i doing wrong here ?

2.x QueueEmail fails if passing CakeEmail instead of array

Data is

a:1:{s:8:"settings";O:9:"CakeEmail":36:{s:6:" * _to";a:1:{s:19:"[email protected]";s:19:"[email protected]";}s:8:" * _from";a:1:{s:18:"[email protected]";s:8:"TeamCash";}s:10:" * _sender";a:0:{}s:11:" * _replyTo";a:0:{}s:15:" * _readReceipt";a:0:{}s:14:" * _returnPath";a:0:{}s:6:" * _cc";a:0:{}s:7:" * _bcc";a:0:{}s:13:" * _messageId";b:1;s:10:" * _domain";s:15:"DESKTOP-RBHJA57";s:11:" * _subject";s:5:"About";s:11:" * _headers";a:0:{}s:10:" * _layout";s:7:"default";s:12:" * _template";s:0:"";s:14:" * _viewRender";s:4:"View";s:12:" * _viewVars";a:0:{}s:9:" * _theme";N;s:11:" * _helpers";a:1:{i:0;s:4:"Html";}s:15:" * _textMessage";s:0:"";s:15:" * _htmlMessage";s:0:"";s:11:" * _message";a:0:{}s:24:" * _emailFormatAvailable";a:3:{i:0;s:4:"text";i:1;s:4:"html";i:2;s:4:"both";}s:15:" * _emailFormat";s:4:"text";s:17:" * _transportName";s:18:"Mailchimp.Mandrill";s:18:" * _transportClass";O:17:"MandrillTransport":4:{s:9:" * _Email";N;s:10:" * _Socket";N;s:11:" * _headers";N;s:10:" * _config";a:2:{s:3:"key";s:22:"validkey";s:11:"useTemplate";b:1;}}s:7:"charset";s:5:"UTF-8";s:13:"headerCharset";s:5:"UTF-8";s:14:" * _appCharset";s:5:"UTF-8";s:15:" * _attachments";a:0:{}s:12:" * _boundary";N;s:10:" * _config";a:3:{s:9:"transport";s:18:"Mailchimp.Mandrill";s:3:"key";s:22:"validkey";s:11:"useTemplate";b:1;}s:15:" * _charset8bit";a:2:{i:0;s:5:"UTF-8";i:1;s:9:"SHIFT_JIS";}s:22:" * _contentTypeCharset";a:1:{s:14:"ISO-2022-JP-MS";s:11:"ISO-2022-JP";}s:16:" * _emailPattern";s:59:"/^((?:[\p{L}0-9.!#$%&'*+\/=?^_{|}~-]+)*@[\p{L}0-9-.]+)$/ui";s:15:" * _configClass";s:11:"EmailConfig";s:18:" * _configInstance";O:11:"EmailConfig":1:{s:7:"default";a:3:{s:9:"transport";s:18:"Mailchimp.Mandrill";s:3:"key";s:22:"validkey";s:11:"useTemplate";b:1;}}}}

Error outputed is

[2016-02-01 16:41:08] Looking for Job ...
Running Job of type "Email"
Warning Error: array_merge(): Argument #2 is not an array in [C:\Users\chall\teamcash-website\public_html\Plugin\Queue\Console\Command\Task\QueueEmailTask.php, line 99]

Warning Error: Invalid argument supplied for foreach() in [C:\Users\chall\teamcash-website\public_html\Plugin\Queue\Console\Command\Task\QueueEmailTask.php, line 100]

2016-02-01 16:41:08 Error: You need to specify at least one destination for to, cc or bcc. (line 1164 in C:\Users\chall\teamcash-website\Vendor\cakephp\cakephp\lib\Cake\Network\Email\CakeEmail.php)

0 C:\Users\chall\teamcash-website\public_html\Plugin\Tools\Lib\EmailLib.php(531): CakeEmail->send(NULL)

1 C:\Users\chall\teamcash-website\public_html\Plugin\Queue\Console\Command\Task\QueueEmailTask.php(110): EmailLib->send(NULL)

2 C:\Users\chall\teamcash-website\public_html\Plugin\Queue\Console\Command\QueueShell.php(216): QueueEmailTask->run(Array, '17')

3 C:\Users\chall\teamcash-website\Vendor\cakephp\cakephp\lib\Cake\Console\Shell.php(451): QueueShell->runworker()

4 C:\Users\chall\teamcash-website\Vendor\cakephp\cakephp\lib\Cake\Console\ShellDispatcher.php(212): Shell->runCommand('runworker', Array)

5 C:\Users\chall\teamcash-website\Vendor\cakephp\cakephp\lib\Cake\Console\ShellDispatcher.php(66): ShellDispatcher->dispatch()

6 C:\Users\chall\teamcash-website\public_html\Console\cake.php(48): ShellDispatcher::run(Array)

7 {main}

Job did not finish, requeued.

I would expect the job to complete successfully since I already provided a complete CakeEmail object to the createJob('email', $CakeEmail);

Email queue fails if SMTP Transport is being used (CakePHP v3.x)

Using Mail transport

---------------------------------------------------------------
Looking for Job....
Running Job of type "Email"
Job Finished.
---------------------------------------------------------------

Using SMTP transport - (email changed)

Looking for Job....
Running Job of type "Email"
2016-02-12 02:43:55 Error: Cake\Mailer\Transport\SmtpTransport - TO:[email protected]||FROM:[email protected]||REPLY:||S:testing
2016-02-12 02:43:55 Error: SMTP Error: 501 <>: missing or malformed local part (line 449 in C:\xampp\htdocs\cakeproj\vendor\cakephp\cakephp\src\Mailer\Transport\SmtpTransport.php)
#0 C:\xampp\htdocs\cakeproj\vendor\cakephp\cakephp\src\Mailer\Transport\SmtpTransport.php(366): Cake\Mailer\Transport\SmtpTransport->_smtpSend('RCPT TO:<>')
#1 C:\xampp\htdocs\cakeproj\vendor\cakephp\cakephp\src\Mailer\Transport\SmtpTransport.php(168): Cake\Mailer\Transport\SmtpTransport->_sendRcpt(Object(Tools\Mailer\Email))
#2 C:\xampp\htdocs\cakeproj\vendor\cakephp\cakephp\src\Mailer\Email.php(1303): Cake\Mailer\Transport\SmtpTransport->send(Object(Tools\Mailer\Email))
#3 C:\xampp\htdocs\cakeproj\vendor\dereuromark\cakephp-tools\src\Mailer\Email.php(463): Cake\Mailer\Email->send(NULL)
#4 C:\xampp\htdocs\cakeproj\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php(113): Tools\Mailer\Email->send(NULL)
#5 C:\xampp\htdocs\cakeproj\vendor\dereuromark\cakephp-queue\src\Shell\QueueShell.php(212): Queue\Shell\Task\QueueEmailTask->run(Array, 45)
#6 [internal function]: Queue\Shell\QueueShell->runworker()
#7 C:\xampp\htdocs\cakeproj\vendor\cakephp\cakephp\src\Console\Shell.php(444): call_user_func_array(Array, Array)
#8 C:\xampp\htdocs\cakeproj\vendor\cakephp\cakephp\src\Console\ShellDispatcher.php(217): Cake\Console\Shell->runCommand(Array, true, Array)
#9 C:\xampp\htdocs\cakeproj\vendor\cakephp\cakephp\src\Console\ShellDispatcher.php(181): Cake\Console\ShellDispatcher->_dispatch(Array)
#10 C:\xampp\htdocs\cakeproj\vendor\cakephp\cakephp\src\Console\ShellDispatcher.php(127): Cake\Console\ShellDispatcher->dispatch(Array)
#11 C:\xampp\htdocs\cakeproj\bin\cake.php(33): Cake\Console\ShellDispatcher::run(Array)
#12 {main}
Job did not finish, requeued.

The code used:

        $this->loadModel('Queue.QueuedTasks');
        $this->QueuedTasks->createJob('Email', [
            'settings' => [
                'to' => ['[email protected]'],
                'from' => ['[email protected]'],
                'subject' => 'testing',
                'template' => 'registration',
                'emailFormat' => 'html'
            ],
            'vars' => [
                'name' => 'tester'
            ]
        ]);

Can you please advice on the issue?

Thanks and great work on the plugin. Keep it up.

Basic support to Postgresql

Hello,

I've tried to use the plugin with postgres and it seems to have an error on the QueuedTasksTable.
The query expression written is only compatible with MySQL in the following part:

<?php
      public function requestJob(array $capabilities, $group = null) {
        $now = new Time();
        $nowStr = $now->toDateTimeString();

        $query = $this->find();
        $findCond = [
            'conditions' => [
                'completed IS' => null,
                'OR' => [],
            ],
            'fields' => [
                'age' => $query->newExpr()->add('IFNULL(TIMESTAMPDIFF(SECOND, "' . $nowStr . '", notbefore), 0)')
            ],
            'order' => [
                'age ASC',
                'id ASC',
            ]
        ];

If you instruct me on how I could solve this I can send a PR. This is somehow a pretty difficult expression to be written in a generic way for all databases.
In postgres it would be something like this:

SELECT IFNULL(EXTRACT(EPOCH FROM ( notbefore - NOW() ), 0)
FROM queued_tasks

plugin folder name issue

just installed the plugin via composer, the plugin installed under /Plugin/CakephpQueue.
in order to create schema i needed to run cake Schema create -p CakephpQueue --name Queue - the readme should be updated accordingly

Queue performance on CakePHP 2.x

We've been successfully using the Queue plugin on CakePHP 2.x sites for a while now, but on one site having issues with it running very slowly. The queue contains a large number of tasks for generating statistics and sending out emails in the background.

We've currently got it setup to run every 5 minutes via cron with the following configuration:-

$config['Queue'] = array(
    // seconds to sleep() when no executable job is found
    'sleeptime' => 10,

    // probability in percent of a old job cleanup happening
    'gcprob' => 10,

    // time (in seconds) after which a job is requeued if the worker doesn't report back
    'defaultworkertimeout' => 120,

    // number of retries if a job fails or times out.
    'defaultworkerretries' => 4,

    // seconds of running time after which the worker will terminate (0 = unlimited)
    'workermaxruntime' => 300,

    // minimum time (in seconds) which a task remains in the database before being cleaned up.
    'cleanuptimeout' => 2592000,

    // instruct a Workerprocess quit when there are no more tasks for it to execute (true = exit, false = keep running)
    'exitwhennothingtodo' => true,

    // pid file path directory (by default goes to the app/tmp/queue folder)
    'pidfilepath' => TMP . 'queue' . DS,

    // determine whether logging is enabled
    'log' => true,

    // set to false to disable (tmp = file in TMP dir)
    'notify' => 'tmp'
);

Is there any way we could improve the queue's performance? Are we maybe missing something in our config? Even basic tasks that just perform a couple of simple queries appear to run slow at the moment.

We're looking at rewriting a number of our tasks to try and optimise them, but we would have expected to see the queue running faster than it currently does regardless.

Any suggestions would be greatly appreciated.

Unserialize giving offset error

I am always getting this error when running the worker

Notice Error: unserialize(): Error at offset 193 of 65535 bytes in [/var/www/clients/client1/web7/web/vendor/dereuromark/cakephp-queue/src/Shell/QueueShell.php, line 212]

2016-03-15 15:13:43 Notice: Notice (8): unserialize(): Error at offset 193 of 65535 bytes in [/var/www/clients/client1/web7/web/vendor/dereuromark/cakephp-queue/src/Shell/QueueShell.php, line 212]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE/src/Error/BaseErrorHandler.php, line 146
unserialize - [internal], line ??
Queue\Shell\QueueShell::runworker() - ROOT/vendor/dereuromark/cakephp-queue/src/Shell/QueueShell.php, line 212
Cake\Console\Shell::runCommand() - CORE/src/Console/Shell.php, line 444
Cake\Console\ShellDispatcher::_dispatch() - CORE/src/Console/ShellDispatcher.php, line 217
Cake\Console\ShellDispatcher::dispatch() - CORE/src/Console/ShellDispatcher.php, line 181
Cake\Console\ShellDispatcher::run() - CORE/src/Console/ShellDispatcher.php, line 127
[main] - ROOT/bin/cake.php, line 33

How about using BLOB type instead of TEXT in the database, to fix character encoding bugs.

Error loading custom tasks Cake 3

Hello,

Having issue loading custom tasks for Cake 3.0.8.

Created custom task Shell/Task/QueueExample2Task.php it shows up when running ./bin/cake Queue.Queue

Available Tasks:
    * Example2
    * Email
    * Example
    * Execute
    * LongExample
    * RetryExample
    * SuperExample

But when running ./bin/cake Queue.Queue add Example2 the follow error shows up in terminal.

Exception: Task class QueueExample2 could not be found. in [/Users/lmackay/Desktop/test_app/vendor/cakephp/cakephp/src/Console/TaskRegistry.php, line 70]
2015-07-19 07:37:19 Error: [Cake\Console\Exception\MissingTaskException] Task class QueueExample2 could not be found.
Exception Attributes: array (
  'class' => 'QueueExample2',
  'plugin' => NULL,
)
Stack Trace:
#0 /Users/lmackay/Desktop/test_app/vendor/cakephp/cakephp/src/Core/ObjectRegistry.php(90): Cake\Console\TaskRegistry->_throwMissingClassError('QueueExample2', NULL)
#1 /Users/lmackay/Desktop/test_app/vendor/cakephp/cakephp/src/Console/Shell.php(441): Cake\Core\ObjectRegistry->load('QueueExample2', Array)
#2 /Users/lmackay/Desktop/test_app/vendor/dereuromark/cakephp-queue/src/Shell/QueueShell.php(119): Cake\Console\Shell->__get('QueueExample2')
#3 [internal function]: Queue\Shell\QueueShell->add('Example2')
#4 /Users/lmackay/Desktop/test_app/vendor/cakephp/cakephp/src/Console/Shell.php(380): call_user_func_array(Array, Array)
#5 /Users/lmackay/Desktop/test_app/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(204): Cake\Console\Shell->runCommand(Array, true)
#6 /Users/lmackay/Desktop/test_app/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(175): Cake\Console\ShellDispatcher->_dispatch()
#7 /Users/lmackay/Desktop/test_app/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(126): Cake\Console\ShellDispatcher->dispatch()
#8 /Users/lmackay/Desktop/test_app/bin/cake.php(33): Cake\Console\ShellDispatcher::run(Array)
#9 {main}

it seems that it's trying to load the task relative to the Plugin path. Putting the file in dereuromark/cakephp-queue/src/Shell/Task/QueueExample2Task.php makes it work.

Looked into the error a bit further and tasks are loading in via /cakephp/src/Core/ObjectRegistry.php's load method. It takes a $config key called "className" and can alias classes \App\Shell\Task\QueueExample2Task so maybe it needs to do that for custom tasks in the QueueShell->initialize()

Or maybe I'm just not using this plugin right, which would be great. It looks like a very good plugin, thank you.

Custom task failure

Hi,
I try to run a custom task and got an exception error: Task class QueueGetkey could not be found.

The file is located under src/shell/task and named appropriately and contains: use Queue\Shell\Task\QueueTask; as stated in the doc.

The namespace is changed too.

I suppose i miss something obvious but so far i can't see what.

Thanks for your support !

Can't use custom APP task with same name as one in Queue plugin

I tried to copy the QueueEmailTask.php to my App so I could make my own custom email task, but it keeps running the plugin version.

In QueueShell::initialize() if you switch around the searching of the tasks such that APP tasks are loaded after plugins, then the app version would override the plugin version and it works.

I'm not sure if this is a big enough deal for you to want to make the change. I just thought I'd point it out.

completed datetime wrong

Hi found a little issue at line 272...

following worked for me.
src/Model/Table/QueuedJobsTable.php line 271

$fields = [ 'completed' => new Time(), ];

Thanks

Notify user about task completion or failure

I need to implement some sort of notification to users when a task has completed or failed. What would be the best method?

I've thought about the following possibilities:

Add user_id, model, and foreign_key fields to queued_tasks table

This would reference any record that is being processed and the user that caused the task to be created. The queued_tasks table would be queried for each user looking for completed or failed tasks.

Add UserTask model in App

Keep user_id, model, and foreign_key in app's own model along with queued_task_id, which the QueuedTask::createJob() method would have to return instead of true upon save.
This would be queried just like the above.

What are your thoughts?

Feature request: Garbage cleanup only after amount of time

Awesome tool! We are using it in our project.

In my project, I don't want to clean up old jobs for about a week. That way, if there is a problem, I'll have a little history to look back on.

I am accomplishing this today by setting:

$config['Queue']['gcprop'] = 0;

and then running a separate process weekly to clear the queue of old jobs.

But it would be nice to have this built into cakephp-queue. How about a setting like:

$config['Queue']['gcminage'] = 604800; // one week in seconds

gcminage stands for 'garbage collection minimum age'. Meaning, it won't consider a job as garbage unless it is a certain age, thus it won't clean it out.

This setting would be orthogonal to 'gcprop'. Regardless of the chance of garbage collection, when it runs, it will respect the age of the job and only delete it if appropriate.

What do you think?

Job not found

Hi,
i installed everything like in the Doc. Plugin Working, jobs can be created.
I want to run a job in my custom task with the name "Notification".
I have the following job in the database: (i removed the data)

`id`, `job_type`, `data`, `job_group`, `reference`, `created`, `notbefore`, `fetched`, `completed`, `progress`, `failed`, `failure_message`, `workerkey`, `status`, `priority`

19, 'Notification', '', NULL, NULL, '2017-02-28 19:39:34', NULL, '2017-02-28 19:43:31', '2017-02-28 19:43:31', NULL, 0, NULL, 'd8a4fd0c83758f61e3ad5253e4ea772472083920', NULL, 5

(Sorry i wanted to upload a picture but it fails at Gitlab. 37kb image upload not working.

The job was added with the command:
TableRegistry::get('Queue.QueuedJobs')->createJob('Notification', $notification);

The following file is placed in the src/Shell/Task folder:

<?php
namespace App\Shell\Task;
use Queue\Shell\Task\QueueTask;
class QueueNotificationTask extends QueueTask
{
	public function run(array $data, $id) {

		//$this->processNotificationJob($data);

		return true;
	}

The task is recognized and when i exec
./bin/cake.php queue status
i get:

Available Tasks:
* Notification
* Email
* Example
* Execute
* LongExample
* RetryExample
* SuperExample

But when i run
./bin/cake.php queue runworker
while i am in the app home the job will not be found. I just get:
[2017-02-28 19:55:44] Looking for Job ... nothing to do, sleeping.

So basicly the task will be found but not the job that is in the database.

I use PHP 5.5.19 and CakePHP v3.3.11.

Any ideas?

Thanks a lot!

Creating Execute task with multiple commands in a line

Hi, thanks for the super useful plugin which I think is much better than Resque for performing basic background/queued tasks.

This post is more of a query than an issue report:
My implementation of this plugin went pretty well so far and have no complaints.
I want to queue a job from my controller which will first change directory then execute a script in that directory like cd /path/to/scripts/directory && php myscript.php some_argument. Right now, my code in controller is

$queue_data = array(
    'command' => 'php',
    'params' => array(
        '/path/to/scripts/directory/myscript.php',
        'some_argument',
    )
);

$this->QueuedTask->createJob('Execute', $queue_data);

which executes the command php /path/to/scripts/directory/myscript.php some_argument

Is there a way that I can modify this controller code to include multiple commands to be run together like I said above. This is just an example, I'm planning to execute few other linked scripts that have relative paths inside them. So, if I try to call those scripts from any other directory, they will error out. I do not want to use absolute paths in the files because it will be a pain when I move my files from development to production server with different paths.

[Question] Nested Tasks

Hi @dereuromark ,
Is it possible to call a task inside another task file ?
eg.:
A task generate a pdf file(QueuePdfTask.php), inside the run method after generating the pdf file send an email using another task(QueueEmailTask.pdf)

Thanks

20161319000000_increase_data_size.php fails on Postgres

When running this Queue migration on Postgres I get the following error.

[PDOException]                                                               
  SQLSTATE[42601]: Syntax error: 7 ERROR:  type modifier is not allowed for t  
  ype "text" 

If I comment out the following then the migration run fine.

$table->changeColumn('data', 'text', [
            // 'length' => 4294967295,
            'null' => true,
            // 'default' => null,
        ]);

Is this column change needed?

Shell is not working with cake 2.x

I am using cakephp 2.4. here is my command and its output
command:
H:\xampp\htdocs\demobackup\app\Console>cake Queue.Queue
output:
Error: Plugin Queue could not be found.
#0 H:\xampp\htdocs\demobackup\lib\Cake\Core\App.php(367):

CakePlugin::path('Queue')
#1 H:\xampp\htdocs\demobackup\lib\Cake\Core\App.php(228):

App::pluginPath('Queue')
#2 H:\xampp\htdocs\demobackup\lib\Cake\Core\App.php(549):

App::path('Console/Command', 'Queue')
#3 [internal function]: App::load('QueueShell')
#4 [internal function]: spl_autoload_call('QueueShell')
#5 H:\xampp\htdocs\demobackup\lib\Cake\Console\ShellDispa

tcher.php(250): class_exists('QueueShell')
#6 H:\xampp\htdocs\demobackup\lib\Cake\Console\ShellDispa

tcher.php(200): ShellDispatcher->_getShell('Queue.Queue')
#7 H:\xampp\htdocs\demobackup\lib\Cake\Console\ShellDispa

tcher.php(68): ShellDispatcher->dispatch()
#8 H:\xampp\htdocs\demobackup\app\Console\cake.php(37): S

hellDispatcher::run(Array)
#9 {main}

I have added in bootstrap.php
CakePlugin::loadAll();

all other plugins are working fine. Please help

CakePHP 3.0

This queue plugin would be great to have also for 3.0 version ๐Ÿ‘

Failing unit tests with Sqlite driver

I notice that if you try and run unit tests without any database parameters in the environment, the tests default to the Sqlite driver.

Looking over the codebase, it looks like there are many different instances of MySQL-isms in the code. It would be nice if this plugin was database-agnostic.

update in jobRequest on mysql cluster throws error

looks like this specific combination of 'update', 'text' field type, 'order by' datetime & mysql cluster throws error:

[PDOException] SQLSTATE[HY000]: General error: 1296 Got error 4265 'The method is not valid in current blob state' from NDBCLUSTER

while it looks like it can be mysql cluster bug (works ok with InnoDB engine) is the order by even necessary? its already ordered in first query

Note on Setting up the trigger cronjob in README

I had few problems when I added the queue worker to my crontab because of my stupidity, of course. I had created the cron job using crontab -e while I was superuser. That created few cache files that were owned by root and then I started having app performance issues due to problems with cache.

All I had to do was remove the cron job from my root crontab and put it into www-data crontab by using crontab -u www-data -e. I noticed that you did comment this on one of the closed issues here. But I feel it will be a favor to write it down in README for many hasty people (like myself ๐Ÿ˜ฅ )

Thanks again for the plugin!

Composer installation for CakePHP 3 inaccuracy

You've stated in your readme file that you can install with composer using require dereuromark/cakephp-queue:3.0 for CakePHP 3 but don't appear to have tagged the repository with this version number yet.

shell issuse in cakephp2.4

Hello,
sir i have problem in shell loading in cakephp 2.4 but does understand how to solve this. When i type "Console/cake Queue.Queue " in cake console and my home directory is
cake>app>Console/cake Queue.Queue
Error: Shell class QueueShell could not be found.
#0 /var/www/html/cake1/lib/Cake/Console/ShellDispatcher.php(203): ShellDispatcher->_getShell('Queue.Queue')
#1 /var/www/html/cake1/lib/Cake/Console/ShellDispatcher.php(66): ShellDispatcher->dispatch()
#2 /var/www/html/cake1/app/Console/cake.php(47): ShellDispatcher::run(Array)
#3 {main}

Please Help Me..

Unable to send email via command line using runworker

Hi,
I am trying to implement the 2.x version of this plugin in my cakephp V2.6.1. I have installed it correctly. Updated the database with new tables. Then made an action in controller to add email tasks in queue. Till this point everything is working fine. But while running the Queue from the command line. I am getting the following error.

Running Job of type "Email"
Queue Email task called without settings data.
Job did not finish, requeued.

Wrong path with compser

When installing cakephp-queue for CakePHP 3.X with composer, the path for this Plugin in "vendor/cakephp-plugins.php" looks like:
'Queue' => $baseDir . '/vendor/dereuromark/cakephp-queue/'
but should be:
'Queue' => $baseDir . '/vendor/dereuromark/Queue/'
this results in:
Exception: Could not load configuration file: .../vendor/dereuromark/cakephp-queue/config\queue.php in [...\vendor\cakephp\cakephp\src\Core\Configure\FileConfigTrait.php, line 59]

Broken "Reset Queue Tasks" button

Hi Mark,

I'm using the 2.x version of your plugin. The "Reset Queue Tasks" button on "queue/queue/admin_index" page posts to the "reset" action, however the action is named "admin_reset". So the button is not working. Is this a bug? or how can I fix it.

Thanks

Prep 3.1.0 release

We need the tests to work again for this.

I could need a helping hand as the tests still fail for the "rate limit", seems like the 3.x upgrade wasnt fully BC yet.

Getting emails twice from Queue

Hello Mark,
First of all big thank to you for developing such a nice plugin.
I have used this plugin in my web application which is developed under cakephp 2.x version. Issue I am facing when I am adding a send Email task into Queue, it will send email twice to each recipients.
After debugging this issue I found that there are neither duplicate entries into the queued_task table nor repeated users data to send email.
Can you please provide a solution for this ?

worker running more than its life set in config file

I set worker life workermaxruntime = 6000 and set a crontab to run a worker after 10 minutes but after 5 hours i have a 10 workers active. what is this ??

Please let me know why this is happening and is it a bug

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.