Skip to content

Commit

Permalink
Remove option to randomly select jobs
Browse files Browse the repository at this point in the history
The random selection was taken from DJJob to prevent lock contention,
but that is not applicable when jobs are executed by a scheduled cron
job.
  • Loading branch information
jkowens committed Oct 11, 2018
1 parent 8d34279 commit 6ea67ad
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
10 changes: 2 additions & 8 deletions app/code/community/Jowens/JobQueue/Model/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,8 @@ public function executeJobs($schedule=null) {
array('locked_by', 'eq' => $this->workerName)
))
->addFieldToFilter('failed_at', array('null' => true))
->addFieldToFilter('attempts', array('lt' => (int)Mage::getStoreConfig('jobqueue/config/max_attempts')));

if (Mage::getStoreConfigFlag('jobqueue/config/sort_random')) {
// randomly order to prevent lock contention among workers
$collection->getSelect()->order(new Zend_Db_Expr('RAND()'));
} else {
$collection->setOrder('id','ASC');
}
->addFieldToFilter('attempts', array('lt' => (int)Mage::getStoreConfig('jobqueue/config/max_attempts')))
->setOrder('id','ASC');

$limit = Mage::getStoreConfig('jobqueue/config/limit_jobs');
if ($limit > 0) {
Expand Down
1 change: 0 additions & 1 deletion app/code/community/Jowens/JobQueue/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
<cron_expr>*/5 * * * *</cron_expr>
<max_attempts>10</max_attempts>
<limit_jobs>1000</limit_jobs>
<sort_random>1</sort_random>
<queue>default</queue>
<log_level>0</log_level>
</config>
Expand Down
9 changes: 1 addition & 8 deletions app/code/community/Jowens/JobQueue/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@
<show_in_default>1</show_in_default>
<comment>Set to 0 to have no limit</comment>
</limit_jobs>
<sort_random>
<label>Sort Jobs Randomly</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<show_in_default>1</show_in_default>
<sort_order>52</sort_order>
</sort_random>
<queue>
<label>Queue</label>
<frontend_type>text</frontend_type>
Expand All @@ -66,4 +59,4 @@
</groups>
</jobqueue>
</sections>
</config>
</config>

0 comments on commit 6ea67ad

Please sign in to comment.