/
importer.py
41 lines (30 loc) · 1.16 KB
/
importer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from gettext import gettext as _
import logging
from celery import shared_task
from pulpcore.app import models
from pulpcore.tasking.services import storage
from pulpcore.tasking.tasks import UserFacingTask
log = logging.getLogger(__name__)
@shared_task(base=UserFacingTask)
def sync(importer_pk):
"""
Call sync on the importer defined by a plugin.
Check that the importer has a feed_url, which is necessary to sync. A working directory
is prepared, the plugin's sync is called, and then working directory is removed.
Args:
importer_pk (str): The importer PK.
Raises:
ValueError: When feed_url is empty.
"""
importer = models.Importer.objects.get(pk=importer_pk).cast()
if not importer.feed_url:
raise ValueError(_("An importer must have a 'feed_url' attribute to sync."))
with storage.working_dir_context() as working_dir:
importer.working_dir = working_dir
log.info(
_('Starting sync: repository=%(repository)s importer=%(importer)s'),
{
'repository': importer.repository.name,
'importer': importer.name
})
importer.sync()