Active
Project:
Job queue
Version:
6.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
24 Mar 2010 at 11:11 UTC
Updated:
24 Mar 2010 at 11:11 UTC
Hi,
I propose to delete job from database right after we're sure that function to be executed is exists.
Because right now here are 2 potential cases, when function might be executed 2+ times:
1. Another instance of cron fired before 1st instance is done
2. Script will terminate execution by timeout or memory limit.
So the final version of the function should looks like this:
function job_queue_dequeue() {
$job = db_fetch_object(db_query_range('SELECT jqid, description, function, arguments, file FROM {job_queue} WHERE priority <> %d ORDER BY priority, jqid', JOB_QUEUE_DO_NOT_RUN, 0, 1));
if ($job === FALSE) {
return FALSE;
}
if (!empty($job->file)) {
include_once './'. $job->file;
}
if (function_exists($job->function)) {
db_query('DELETE FROM {job_queue} WHERE jqid = %d', $job->jqid);
$arguments = unserialize($job->arguments);
call_user_func_array($job->function, $arguments);
// Filter objects out of arguments
watchdog('job_queue', 'Ran queued job "!description"', array('!description' => t($job->description, array_filter($arguments, 'is_scalar'))));
}
else {
watchdog('job_queue', 'Failed to run queued job "!description" because the function %function is not defined.', array('!description' => $job->description, '%function' => $job->function), WATCHDOG_ERROR);
}
return TRUE;
}