Index: job_queue.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/job_queue/job_queue.module,v
retrieving revision 1.7.2.2
diff -u -r1.7.2.2 job_queue.module
--- job_queue.module	4 Oct 2009 23:39:05 -0000	1.7.2.2
+++ job_queue.module	23 Nov 2009 02:36:12 -0000
@@ -123,11 +123,23 @@
   if (empty($max_execution_time)) {
     $max_execution_time = 5 * 60;
   }
-  while ($job_count > 0 && job_queue_dequeue()) {
-    if ((timer_read('page') / 1000) > ($max_execution_time / 2)) {
-      break; // Stop once we have used over half of the maximum execution time or exceeds the original number of jobs.
+  if ($job_limit = variable_get('job_queue_limit', 0)) {
+    $i = 0; //counter if limit is used
+    while ($job_count > 0 && job_queue_dequeue() && $i < $job_limit) {
+      $i++;
+      if ((timer_read('page') / 1000) > ($max_execution_time / 2)) {
+        break; // Stop once we have used over half of the maximum execution time or exceeds the original number of jobs.
+      }
+      $job_count -= 1;
+    }
+  }
+  else {
+    while ($job_count > 0 && job_queue_dequeue()) {
+      if ((timer_read('page') / 1000) > ($max_execution_time / 2)) {
+        break; // Stop once we have used over half of the maximum execution time or exceeds the original number of jobs.
+      }
+      $job_count -= 1;
     }
-    $job_count -= 1;
   }
 }
 
@@ -183,6 +195,14 @@
 
   $form = array();
 
+  $form['job_queue_limit'] = array(
+    '#type' => 'textfield',
+    '#default_value' => variable_get('job_queue_limit', 0),
+    '#required' => TRUE,
+    '#title' => t('Number of jobs per cron run'),
+    '#description' => t('Set the value to 0 for umlimited.'),
+    '#size' => 5,
+  );
   $form['priorities'] = array(
     '#theme' => 'job_queue_priorities_table',
     '#tree' => TRUE,
@@ -232,10 +252,13 @@
 }
 
 function job_queue_settings_form_submit($form, &$form_state) {
-  foreach ($form_state['values']['priorities'] as $function => $data) {
-    db_query("DELETE FROM {job_queue_functions} WHERE function = '%s'", $function);
-    db_query("INSERT INTO {job_queue_functions} (function, priority) VALUES ('%s', %d)", $function, $data['priority']);
-    db_query("UPDATE {job_queue} SET priority = %d WHERE function = '%s'", $data['priority'], $function);
+  if (isset($form_state['values']['priorities'])) {
+    foreach ($form_state['values']['priorities'] as $function => $data) {
+      db_query("DELETE FROM {job_queue_functions} WHERE function = '%s'", $function);
+      db_query("INSERT INTO {job_queue_functions} (function, priority) VALUES ('%s', %d)", $function, $data['priority']);
+      db_query("UPDATE {job_queue} SET priority = %d WHERE function = '%s'", $data['priority'], $function);
+    }
   }
+  variable_set('job_queue_limit', $form_state['values']['job_queue_limit']);
   drupal_set_message(t('Saved job queue settings.'));
 }
Index: .project
===================================================================
RCS file: .project
diff -N .project
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ .project	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>job_queue</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+	</buildSpec>
+	<natures>
+	</natures>
+</projectDescription>
