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
d9135600
Commit
d9135600
authored
Apr 17, 2012
by
catch
Browse files
Issue
#1509996
by jhedstrom: Added Convert hook_cron_queue_info() to hook_queue_info().
parent
5de2f764
Changes
3
Hide whitespace changes
Inline
Side-by-side
core/includes/common.inc
View file @
d9135600
...
...
@@ -5305,8 +5305,8 @@ function drupal_cron_run() {
$return
=
FALSE
;
// Grab the defined cron queues.
$queues
=
module_invoke_all
(
'
cron_
queue_info'
);
drupal_alter
(
'
cron_
queue_info'
,
$queues
);
$queues
=
module_invoke_all
(
'queue_info'
);
drupal_alter
(
'queue_info'
,
$queues
);
// Try to acquire cron lock.
if
(
!
lock_acquire
(
'cron'
,
240.0
))
{
...
...
@@ -5317,7 +5317,9 @@ function drupal_cron_run() {
// Make sure every queue exists. There is no harm in trying to recreate an
// existing queue.
foreach
(
$queues
as
$queue_name
=>
$info
)
{
queue
(
$queue_name
)
->
createQueue
();
if
(
isset
(
$info
[
'cron'
]))
{
queue
(
$queue_name
)
->
createQueue
();
}
}
// Register shutdown callback.
drupal_register_shutdown_function
(
'drupal_cron_cleanup'
);
...
...
@@ -5345,12 +5347,14 @@ function drupal_cron_run() {
}
foreach
(
$queues
as
$queue_name
=>
$info
)
{
$function
=
$info
[
'worker callback'
];
$end
=
time
()
+
(
isset
(
$info
[
'time'
])
?
$info
[
'time'
]
:
15
);
$queue
=
queue
(
$queue_name
);
while
(
time
()
<
$end
&&
(
$item
=
$queue
->
claimItem
()))
{
$function
(
$item
->
data
);
$queue
->
deleteItem
(
$item
);
if
(
isset
(
$info
[
'cron'
]))
{
$function
=
$info
[
'worker callback'
];
$end
=
time
()
+
(
isset
(
$info
[
'cron'
][
'time'
])
?
$info
[
'cron'
][
'time'
]
:
15
);
$queue
=
queue
(
$queue_name
);
while
(
time
()
<
$end
&&
(
$item
=
$queue
->
claimItem
()))
{
$function
(
$item
->
data
);
$queue
->
deleteItem
(
$item
);
}
}
}
// Restore the user.
...
...
core/modules/aggregator/aggregator.module
View file @
d9135600
...
...
@@ -331,12 +331,15 @@ function aggregator_cron() {
}
/**
* Implements hook_
cron_
queue_info().
* Implements hook_queue_info().
*/
function
aggregator_
cron_
queue_info
()
{
function
aggregator_queue_info
()
{
$queues
[
'aggregator_feeds'
]
=
array
(
'title'
=>
t
(
'Aggregator refresh'
),
'worker callback'
=>
'aggregator_refresh'
,
'time'
=>
60
,
'cron'
=>
array
(
'time'
=>
60
,
),
);
return
$queues
;
}
...
...
core/modules/system/system.api.php
View file @
d9135600
...
...
@@ -120,7 +120,7 @@ function hook_admin_paths_alter(&$paths) {
* Long-running tasks and tasks that could time out, such as retrieving remote
* data, sending email, and intensive file tasks, should use the queue API
* instead of executing the tasks directly. To do this, first define one or
* more queues via hook_
cron_
queue_info(). Then, add items that need to be
* more queues via hook_queue_info(). Then, add items that need to be
* processed to the defined queues.
*/
function
hook_cron
()
{
...
...
@@ -154,22 +154,33 @@ function hook_cron() {
* items in the queue, otherwise it might take several requests, which can be
* run in parallel.
*
* You can create queues, add items to them, claim them, etc without declaring
* the queue in this hook if you want, however, you need to take care of
* processing the items in the queue in that case.
*
* @return
* An associative array where the key is the queue name and the value is
* again an associative array. Possible keys are:
* - 'worker callback': The name of the function to call. It will be called
* with one argument, the item created via
* Drupal\Core\Queue\QueueInterface::createItem() in hook_cron().
* - 'time': (optional) How much time Drupal should spend on calling this
* worker in seconds. Defaults to 15.
* - 'cron': (optional) An associative array containing the optional key:
* - 'time': (optional) How much time Drupal cron should spend on calling
* this worker in seconds. Defaults to 15.
* If the cron key is not defined, the queue will not be processed by cron,
* and must be processed by other means.
*
* @see hook_cron()
* @see hook_
cron_
queue_info_alter()
* @see hook_queue_info_alter()
*/
function
hook_
cron_
queue_info
()
{
function
hook_queue_info
()
{
$queues
[
'aggregator_feeds'
]
=
array
(
'title'
=>
t
(
'Aggregator refresh'
),
'worker callback'
=>
'aggregator_refresh'
,
'time'
=>
60
,
// Only needed if this queue should be processed by cron.
'cron'
=>
array
(
'time'
=>
60
,
),
);
return
$queues
;
}
...
...
@@ -183,13 +194,13 @@ function hook_cron_queue_info() {
* @param array $queues
* An array of cron queue information.
*
* @see hook_
cron_
queue_info()
* @see hook_queue_info()
* @see drupal_cron_run()
*/
function
hook_
cron_
queue_info_alter
(
&
$queues
)
{
function
hook_queue_info_alter
(
&
$queues
)
{
// This site has many feeds so let's spend 90 seconds on each cron run
// updating feeds instead of the default 60.
$queues
[
'aggregator_feeds'
][
'time'
]
=
90
;
$queues
[
'aggregator_feeds'
][
'
cron'
][
'
time'
]
=
90
;
}
/**
...
...
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