Skip to content

Commit 7daba5a

Browse files
Updated slides with clarification.
1 parent e991d96 commit 7daba5a

File tree

1 file changed

+66
-19
lines changed

1 file changed

+66
-19
lines changed

src/slides.md

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,47 @@ Finally, we'll look at how Drupal uses the Queue API internally and some use cas
6363
-->
6464
---
6565

66+
## What Is A Queue?
67+
68+
A queue is a "first in, first out" (or FIFO) data model where items are placed into a list and processed in order.
69+
70+
The first item added is processed first, just like a normal queue.
71+
72+
This is a common structure in programming when processing data.
73+
74+
---
75+
6676
## What Is The Queue API?
6777

68-
Allows tasks to be processed in asynchronously in order to prevent timeout errors or memory problems.
78+
The Queue API creates a queue data structure and allows tasks to be processed in asynchronously. This normally in order to prevent timeout errors or memory problems.
79+
80+
---
81+
82+
## The Queue API
83+
- The API is highly extensible. By default we have a database queue and a memory queue interfaces.
84+
- When creating a queue it is common for the database queue to be used.
85+
- The cron system automatically picks up database queue items and processes them.
6986

7087
---
7188

7289
## The Queue API
7390

7491
- The Queue API in Drupal has no user interface as everything happens behind the scenes.
75-
- The Batch API is built upon the Queue API and uses both the database and memory queues.
92+
- The Batch API is built upon the Queue API and uses both the database and memory queues. The Batch API has an interface that is shown to users when processing tasks.
7693

7794
---
7895

7996
## The Queue API
80-
- The API is highly extensible. By default we have a database queue and a memory queue interfaces.
81-
- When creating a queue it is common for the database queue to be used. The cron system automatically picks up queue items and processes them.
8297

98+
The API consists of three parts:
99+
100+
- A storage interface for the queue.
101+
- The queue worker that will process a single item in the queue.
102+
- A processing step that picks items out the queue and processes it using the worker.
103+
104+
<!--
105+
There are some internal queues that you can use, but you will normally want to create your own queues for processing data.
106+
-->
83107
---
84108

85109
# When To Use A Queue
@@ -96,15 +120,9 @@ For example, let's say you wanted to delete all taxonomy items on a site.
96120

97121
Instead of doing this in one go you would add all of the taxonomy IDs to a queue and process them one by one.
98122

99-
---
100-
101-
## The Queue API
102-
103-
The API consists of three parts:
104-
105-
- A storage interface for the queue.
106-
- The queue worker that will process a single item in the queue.
107-
- A processing step that picks items out the queue and processes it using the worker.
123+
<!--
124+
We'll come onto more examples later, but for now assume that it is possible to throw data into a queue for later processing.
125+
-->
108126

109127
---
110128

@@ -175,6 +193,15 @@ $queue->createItem($item);
175193
176194
```
177195

196+
<!--
197+
The table columns are:
198+
- item_id = An auto increment field.
199+
- name = The name of the queue we created.
200+
- data = The serialised data in our queue.
201+
- expire = When the queue item is picked up for processing the expire time is set to 1 hour in the future. The item can get placed back into the queue, but will be picked back up if the expire time is in the past.
202+
- created = When the queue item was created.
203+
-->
204+
178205
---
179206

180207
## Create A Queue
@@ -195,9 +222,13 @@ A queue worker is required to process the tasks in the queue.
195222

196223
## Create A Queue Worker
197224

198-
- A queue worker is a plugin that accepts single items in the queue.
225+
- A queue worker is a plugin that accepts single items from the queue.
199226
- When Drupal is processing the queue it will pass each item to the processor.
200-
- If everything is processed correctly then
227+
- If everything is processed correctly then the item will be deleted from the queue.
228+
229+
<!--
230+
The assumption is that if you didn't throw an error then the item should be removed.
231+
-->
201232

202233
---
203234
<!-- _footer: "" -->
@@ -233,10 +264,14 @@ public function processItem($data) {
233264
<!-- _footer: "" -->
234265
## Throwing Exceptions During Processing
235266

236-
We can effect the queue in different ways by throwing different exceptions.
267+
We can effect the queue in different ways by throwing different exceptions. Drupal accepts 4.
237268
- `\Drupal\Core\Queue\DelayedRequeueException` - For database queues, the item is added back to the queue and held back for an hour.
238269
- `\Drupal\Core\Queue\RequeueException` - The item is added back into the queue and will be picked up later in the processing.
239270

271+
<!--
272+
Remember the queue structure. If we throw an item into the queue we put it back to the processing list.
273+
-->
274+
240275
---
241276
## Throwing Exceptions During Processing
242277

@@ -247,6 +282,10 @@ We can effect the queue in different ways by throwing different exceptions.
247282

248283
# Processing A Queue
249284

285+
---
286+
287+
## Processing A Queue
288+
250289
The eaiest way to process a queue is to run cron.
251290

252291
- Via the cron processor form at "/admin/config/system/cron".
@@ -257,7 +296,7 @@ The eaiest way to process a queue is to run cron.
257296
## Processing A Queue
258297

259298
- It is possible to process queues outside of cron.
260-
- Use the queue factory to load the queue and the queue worker plugin to process the item.
299+
- Use the `queue` factory to load the queue and the queue worker plugin to process the item.
261300

262301
```php
263302
$queue = \Drupal::service('queue')->get('queue_simple_example');
@@ -298,9 +337,16 @@ Some live demos!
298337
<!-- _footer: "" -->
299338

300339
## Top Tips
340+
301341
- Keep an eye on the numbers in your queue.
302-
- Think about the amount of time that it would take to process your queue.
303-
- Don't store too much in your queue items, just enough to provide context.
342+
- Think about the amount of time that it would take to process your queue. Is the cron handler running often enough to process the data?
343+
- For large queues, consider storing a (small) array of items in the data. This helps with the speed of processing.
344+
- Don't store too much data in your queue items, just enough to provide context.
345+
346+
---
347+
348+
## Top Tips
349+
304350
- There is no interface for queues so be sure to handle errors properly.
305351
- If your users need to process something straight away then use a batch.
306352

@@ -325,6 +371,7 @@ Some live demos!
325371
## Warmer
326372

327373
- Warms the cache for content entities. Runs this process via a queue.
374+
- The sitemap.xml processing is a good example of storing an array in the queue item.
328375

329376
<small>https://www.drupal.org/project/warmer</small>
330377

0 commit comments

Comments
 (0)