Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setQueuedTime example
->
condition
(
'expires',
$expires
, '>='
)
->
execute
(
)
;
\Drupal::
state
(
)
->
set
(
'mymodule.last_check',
$request_time
)
;
// Long-running operation example, leveraging a queue: // Queue news feeds for updates once their refresh interval has elapsed.
$queue
= \Drupal::
queue
(
'mymodule.feeds'
)
;
$ids
= \Drupal::
entityTypeManager
(
)
->
getStorage
(
'mymodule_feed'
)
->
getFeedIdsToRefresh
(
)
;
foreach
(
Feed::
loadMultiple
(
$ids
)
as
$feed
)
{
if
(
$queue
->
createItem
(
$feed
)
)
{
// Add timestamp to avoid queueing item more than once.
$feed
->
setQueuedTime
(
$request_time
)
;
$feed
->
save
(
)
;
}
}
$ids
= \Drupal::
entityQuery
(
'mymodule_feed'
)
->
accessCheck
(
FALSE
)
->
condition
(
'queued',
$request_time
-
(
3600 * 6
)
, '<'
)
->
execute
(
)
;
if
(
$ids
)
{
$feeds
= Feed::
loadMultiple
(
$ids
)
;
foreach
(
$feeds
as
$feed
)
{
$feed
->
setQueuedTime
(
0
)
;