-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Background adding/updating Manifest index.
- Loading branch information
Showing
3 changed files
with
49 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from celery import Celery | ||
from django.apps import apps | ||
|
||
app = Celery('apps.iiif.manifests', result_extended=True) | ||
|
||
@app.task(name='index_manifest', autoretry_for=(Exception,), retry_backoff=True, max_retries=20) | ||
def index_manifest_task(manifest_id): | ||
"""Background task index Manifest after save. | ||
:param manifest_id: Primary key for .models.Manifest object | ||
:type manifest_id: UUID | ||
""" | ||
from .models import Manifest | ||
from .documents import ManifestDocument | ||
index = ManifestDocument() | ||
manifest = Manifest.objects.get(pk=manifest_id) | ||
index.update(manifest, True, 'index') | ||
|
||
|
||
@app.task(name='de-index_manifest', autoretry_for=(Exception,), retry_backoff=True, max_retries=20) | ||
def de_index_manifest_task(manifest_id): | ||
"""Background task to de-index Manifest after delete. | ||
:param manifest_id: Primary key for .models.Manifest object | ||
:type manifest_id: UUID | ||
""" | ||
from .models import Manifest | ||
from .documents import ManifestDocument | ||
index = ManifestDocument() | ||
manifest = Manifest.objects.get(pk=manifest_id) | ||
index.update(manifest, True, 'delete') |