|
8 | 8 | from django.conf import settings |
9 | 9 | from django.contrib.auth.models import User |
10 | 10 | from django.contrib.contenttypes.models import ContentType |
| 11 | +from django.db import transaction |
11 | 12 | from django.http import HttpResponse, HttpResponseRedirect, Http404 |
12 | 13 | from django.shortcuts import render |
13 | 14 | from django.utils import timezone |
@@ -79,16 +80,28 @@ def notify(request, org, notification): |
79 | 80 | if request.method == "POST": |
80 | 81 | if notification == "index": |
81 | 82 | log("Queuing RFC Editor index sync from notify view POST") |
82 | | - tasks.rfc_editor_index_update_task.delay() |
| 83 | + # Wrap in on_commit so the delayed task cannot start until the view is done with the DB |
| 84 | + transaction.on_commit( |
| 85 | + lambda: tasks.rfc_editor_index_update_task.delay() |
| 86 | + ) |
83 | 87 | elif notification == "queue": |
84 | 88 | log("Queuing RFC Editor queue sync from notify view POST") |
85 | | - tasks.rfc_editor_queue_updates_task.delay() |
| 89 | + # Wrap in on_commit so the delayed task cannot start until the view is done with the DB |
| 90 | + transaction.on_commit( |
| 91 | + lambda: tasks.rfc_editor_queue_updates_task.delay() |
| 92 | + ) |
86 | 93 | elif notification == "changes": |
87 | 94 | log("Queuing IANA changes sync from notify view POST") |
88 | | - tasks.iana_changes_update_task.delay() |
| 95 | + # Wrap in on_commit so the delayed task cannot start until the view is done with the DB |
| 96 | + transaction.on_commit( |
| 97 | + lambda: tasks.iana_changes_update_task.delay() |
| 98 | + ) |
89 | 99 | elif notification == "protocols": |
90 | 100 | log("Queuing IANA protocols sync from notify view POST") |
91 | | - tasks.iana_protocols_update_task.delay() |
| 101 | + # Wrap in on_commit so the delayed task cannot start until the view is done with the DB |
| 102 | + transaction.on_commit( |
| 103 | + lambda: tasks.iana_protocols_update_task.delay() |
| 104 | + ) |
92 | 105 |
|
93 | 106 | return HttpResponse("OK", content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET) |
94 | 107 |
|
|
0 commit comments