wa0x6e / Cake-Resque

Resque plugin for CakePHP : for creating background jobs that can be processed offline later
MIT License
159 stars 56 forks source link

Priority function? #31

Closed dennisoderwald closed 11 years ago

dennisoderwald commented 11 years ago

Hi,

can i give a job a priority? :)

wa0x6e commented 11 years ago

No.

But you can give queues priority

dennisoderwald commented 11 years ago

How?

Can i start 3 Queues with overall 5 workers for all queues?

wa0x6e commented 11 years ago

First, you start workers, not queues. Each workers can poll one or more queues.

You can set 3 queues for each priority : low, medium, high.
Then you push your job into the queues, depending on their priority.

Each queue must be polled by at least one worker, so you should have 3 workers minimum in that case, one for each queue.

You're free to add more workers, like having a worker D and E for the high queue:

That way, your high priority jobs are executed more faster, and independently of the other priority.

There is another definition of priority, that is high priority come before low priority, so when there a high priority job, execute it first, then execute the lower priority jobs. In that case, you need only one worker for all queues:

Just start your worker with start -q "high,medium,low". That worker will poll the 3 queues, in the definition order.

dennisoderwald commented 11 years ago

high medium or low is the queue Name? Or a optional flag in the Configuration?

wa0x6e commented 11 years ago

queue name

dennisoderwald commented 11 years ago

Thanks!

dennisoderwald commented 11 years ago

Is the name of the queue for the priority or the order in the start -q command?

Because I need more than 3 priorities..

wa0x6e commented 11 years ago

-q takes a list of queues. When defining multiple queues, like "queue1,queue2", they are polled in the definition order, so queue1 will always be polled before queue2.

dennisoderwald commented 11 years ago

I must start more queues on a worker with the cli or can define this in the configuration and i use 'start' - all options are loaded and maybe: 5 workers with 3 queues and 1 worker with 1 queue start..? :) Actually i use a own start bash script.. but in the configuration were nice..

wa0x6e commented 11 years ago

You can define your workers settings in the [Queues] section of the config file, then load them using load

dennisoderwald commented 11 years ago

You mean..

        'Queues' => array(
            array(
                'queue' => 'high',  // Use default values from above for missing interval and count indexes
                'user' => 'www-data'    // If PHP is running as a different user on you webserver
            ),
            array(
                'queue' => 'medium',
                'user' => 'www-data'
            ),
            array(
                'queue' => 'low',
                'user' => 'www-data'
            )
        ),

or? But i will 3 workers with high,medium and 1 worker with "low"

wa0x6e commented 11 years ago
'Queues' => array(
            array(
                'queue' => 'high,medium',
                'workers' => 3
            ),
            array(
                'queue' => 'low',
            )
        ),
dennisoderwald commented 11 years ago

Ah thanks kamisama, had the option misunderstood..

dennisoderwald commented 11 years ago

Hm.. only starts 5 workers with the default queue, defined as 'Worker'

        'Worker' => array(
            'queue' => 'medium',        // Name of the default queue
            'interval' => 1,            // Number of second between each poll
            'workers' => 5,             // Number of workers to create
            'user' => 'www-data' ,  // User running the worker process

            // Path to the log file
            // Can be an
            // - absolute path,
            // - an relative path, that will be relative to
            //   app/tmp/logs folder
            // - a simple filename, file will be created inside app/tmp/logs
            'log' => TMP . 'logs' . DS . 'resque-worker-error.log',

            // Log Verbose mode
            // true to log more debugging informations
            // Can also be enabled per worker, by starting with --verbose
            // 'verbose' => true
        ),

Queues defined as your example..

wa0x6e commented 11 years ago

you're starting them with load, aren't you ?

dennisoderwald commented 11 years ago

Ah thx! :)