Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
aae945c3
Commit
aae945c3
authored
Oct 03, 2006
by
Steven Wittens
Browse files
#70995
: Prevent cron re-runs
parent
4bd256a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
includes/common.inc
View file @
aae945c3
...
...
@@ -1698,24 +1698,56 @@ function drupal_cron_run() {
set_time_limit
(
240
);
}
// Check if the last cron run completed
if
(
variable_get
(
'cron_busy'
,
FALSE
))
{
watchdog
(
'cron'
,
t
(
'Last cron run did not complete.'
),
WATCHDOG_WARNING
);
// Fetch the cron semaphore
$semaphore
=
variable_get
(
'cron_semaphore'
,
FALSE
);
if
(
$semaphore
)
{
if
(
time
()
-
$semaphore
>
3600
)
{
// Either cron has been running for more than an hour or the semaphore
// was not reset due to a database error.
watchdog
(
'cron'
,
t
(
'Cron has been running for more than an hour and is most likely stuck.'
),
WATCHDOG_ERROR
);
// Release cron semaphore
variable_del
(
'cron_semaphore'
);
}
else
{
// Cron is still running normally.
watchdog
(
'cron'
,
t
(
'Attempting to re-run cron while it is already running.'
),
WATCHDOG_WARNING
);
}
}
else
{
variable_set
(
'cron_busy'
,
TRUE
);
}
// Register shutdown callback
register_shutdown_function
(
'drupal_cron_cleanup'
);
// Lock cron semaphore
variable_set
(
'cron_semaphore'
,
time
());
// Iterate through the modules calling their cron handlers (if any):
module_invoke_all
(
'cron'
);
// Iterate through the modules calling their cron handlers (if any):
module_invoke_all
(
'cron'
);
// Record cron time
variable_set
(
'cron_last'
,
time
());
watchdog
(
'cron'
,
t
(
'Cron run completed.'
),
WATCHDOG_NOTICE
);
// Clean up
variable_set
(
'cron_busy'
,
FALSE
);
variable_set
(
'cron_last'
,
time
());
watchdog
(
'cron'
,
t
(
'Cron run completed.'
),
WATCHDOG_NOTICE
);
// Release cron semaphore
variable_del
(
'cron_semaphore'
);
// Return TRUE so other functions can check if it did run successfully
return
TRUE
;
// Return TRUE so other functions can check if it did run successfully
return
TRUE
;
}
}
/**
* Shutdown function for cron cleanup.
*/
function
drupal_cron_cleanup
()
{
// See if the semaphore is still locked.
if
(
variable_get
(
'cron_semaphore'
,
FALSE
))
{
watchdog
(
'cron'
,
t
(
'Cron run exceeded the time limit and was aborted.'
),
WATCHDOG_WARNING
);
// Release cron semaphore
variable_del
(
'cron_semaphore'
);
}
}
/**
...
...
modules/system/system.install
View file @
aae945c3
...
...
@@ -3337,6 +3337,11 @@ function system_update_1013() {
return
$ret
;
}
function
system_update_1014
()
{
variable_del
(
'cron_busy'
);
return
array
();
}
/**
* @} End of "defgroup updates-4.7-to-x.x"
* The next series of updates should start at 2000.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment