You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/slides.md
+66-19Lines changed: 66 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,23 +63,47 @@ Finally, we'll look at how Drupal uses the Queue API internally and some use cas
63
63
-->
64
64
---
65
65
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
+
66
76
## What Is The Queue API?
67
77
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.
69
86
70
87
---
71
88
72
89
## The Queue API
73
90
74
91
- 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.
76
93
77
94
---
78
95
79
96
## 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.
82
97
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
+
-->
83
107
---
84
108
85
109
# When To Use A Queue
@@ -96,15 +120,9 @@ For example, let's say you wanted to delete all taxonomy items on a site.
96
120
97
121
Instead of doing this in one go you would add all of the taxonomy IDs to a queue and process them one by one.
98
122
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
+
-->
108
126
109
127
---
110
128
@@ -175,6 +193,15 @@ $queue->createItem($item);
175
193
176
194
```
177
195
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
+
178
205
---
179
206
180
207
## Create A Queue
@@ -195,9 +222,13 @@ A queue worker is required to process the tasks in the queue.
195
222
196
223
## Create A Queue Worker
197
224
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.
199
226
- 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
+
-->
201
232
202
233
---
203
234
<!-- _footer: "" -->
@@ -233,10 +264,14 @@ public function processItem($data) {
233
264
<!-- _footer: "" -->
234
265
## Throwing Exceptions During Processing
235
266
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.
237
268
-`\Drupal\Core\Queue\DelayedRequeueException` - For database queues, the item is added back to the queue and held back for an hour.
238
269
-`\Drupal\Core\Queue\RequeueException` - The item is added back into the queue and will be picked up later in the processing.
239
270
271
+
<!--
272
+
Remember the queue structure. If we throw an item into the queue we put it back to the processing list.
273
+
-->
274
+
240
275
---
241
276
## Throwing Exceptions During Processing
242
277
@@ -247,6 +282,10 @@ We can effect the queue in different ways by throwing different exceptions.
247
282
248
283
# Processing A Queue
249
284
285
+
---
286
+
287
+
## Processing A Queue
288
+
250
289
The eaiest way to process a queue is to run cron.
251
290
252
291
- 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.
257
296
## Processing A Queue
258
297
259
298
- 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.
0 commit comments