Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
f5f204de
Commit
f5f204de
authored
12 years ago
by
Jakob Sack
Browse files
Options
Downloads
Patches
Plain Diff
improve cron.php, add locking for cli cron.php
parent
9cf9d41e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cron.php
+29
-7
29 additions, 7 deletions
cron.php
with
29 additions
and
7 deletions
cron.php
+
29
−
7
View file @
f5f204de
...
@@ -23,9 +23,18 @@
...
@@ -23,9 +23,18 @@
// Unfortunately we need this class for shutdown function
// Unfortunately we need this class for shutdown function
class
my_temporary_cron_class
{
class
my_temporary_cron_class
{
public
static
$sent
=
false
;
public
static
$sent
=
false
;
public
static
$lockfile
=
""
;
public
static
$keeplock
=
false
;
}
}
// We use this function to handle (unexpected) shutdowns
function
handleUnexpectedShutdown
()
{
function
handleUnexpectedShutdown
()
{
// Delete lockfile
if
(
!
my_temporary_cron_class
::
$keeplock
&&
file_exists
(
my_temporary_cron_class
::
$lockfile
)){
unlink
(
my_temporary_cron_class
::
$lockfile
);
}
// Say goodbye if the app did not shutdown properly
if
(
!
my_temporary_cron_class
::
$sent
)
{
if
(
!
my_temporary_cron_class
::
$sent
)
{
if
(
OC
::
$CLI
)
{
if
(
OC
::
$CLI
)
{
echo
'Unexpected error!'
.
PHP_EOL
;
echo
'Unexpected error!'
.
PHP_EOL
;
...
@@ -48,7 +57,7 @@ if( !OC_Config::getValue( 'installed', false )) {
...
@@ -48,7 +57,7 @@ if( !OC_Config::getValue( 'installed', false )) {
register_shutdown_function
(
'handleUnexpectedShutdown'
);
register_shutdown_function
(
'handleUnexpectedShutdown'
);
// Exit if background jobs are disabled!
// Exit if background jobs are disabled!
$appmode
=
OC_
Appconfig
::
getValue
(
'core'
,
'b
ackground
j
ob
s_mode'
,
'ajax'
);
$appmode
=
OC_
B
ackground
J
ob
::
getType
(
);
if
(
$appmode
==
'none'
)
{
if
(
$appmode
==
'none'
)
{
my_temporary_cron_class
::
$sent
=
true
;
my_temporary_cron_class
::
$sent
=
true
;
if
(
OC
::
$CLI
)
{
if
(
OC
::
$CLI
)
{
...
@@ -61,29 +70,42 @@ if( $appmode == 'none' ) {
...
@@ -61,29 +70,42 @@ if( $appmode == 'none' ) {
}
}
if
(
OC
::
$CLI
)
{
if
(
OC
::
$CLI
)
{
// Create lock file first
my_temporary_cron_class
::
$lockfile
=
OC_Config
::
getValue
(
"datadirectory"
,
OC
::
$SERVERROOT
.
'/data'
)
.
'/cron.lock'
;
// We call ownCloud from the CLI (aka cron)
if
(
$appmode
!=
'cron'
)
{
if
(
$appmode
!=
'cron'
)
{
OC_Appconfig
::
setValue
(
'core'
,
'backgroundjobs_mode'
,
'cron'
);
// Use cron in feature!
OC_BackgroundJob
::
setType
(
'cron'
);
}
}
// check if backgroundjobs is still running
// check if backgroundjobs is still running
$pid
=
OC_Appconfig
::
getValue
(
'core'
,
'backgroundjobs_pid'
,
false
);
if
(
file_exists
(
my_temporary_cron_class
::
$lockfile
)){
if
(
$pid
!==
false
)
{
my_temporary_cron_class
::
$keeplock
=
true
;
// FIXME: check if $pid is still alive (*nix/mswin). if so then exit
my_temporary_cron_class
::
$sent
=
true
;
echo
"Another instance of cron.php is still running!"
;
exit
(
1
);
}
}
// save pid
OC_Appconfig
::
setValue
(
'core'
,
'backgroundjobs_pid'
,
getmypid
());
// Create a lock file
touch
(
my_temporary_cron_class
::
$lockfile
);
// Work
// Work
OC_BackgroundJob_Worker
::
doAllSteps
();
OC_BackgroundJob_Worker
::
doAllSteps
();
}
}
else
{
else
{
// We call cron.php from some website
if
(
$appmode
==
'cron'
)
{
if
(
$appmode
==
'cron'
)
{
// Cron is cron :-P
OC_JSON
::
error
(
array
(
'data'
=>
array
(
'message'
=>
'Backgroundjobs are using system cron!'
)));
OC_JSON
::
error
(
array
(
'data'
=>
array
(
'message'
=>
'Backgroundjobs are using system cron!'
)));
}
}
else
{
else
{
// Work and success :-)
OC_BackgroundJob_Worker
::
doNextStep
();
OC_BackgroundJob_Worker
::
doNextStep
();
OC_JSON
::
success
();
OC_JSON
::
success
();
}
}
}
}
// done!
my_temporary_cron_class
::
$sent
=
true
;
my_temporary_cron_class
::
$sent
=
true
;
exit
();
exit
();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment