Skip to content

Action

vds_download_queue(context, query, file, server=None, notifier=None)

Queues a download and returns information about the job and status.

Parameters:

Name Type Description Default
context

the CKAN action context

required
query QueryArgs

the query as a QueryArgs object

required
file DerivativeArgs

the file options as a DerivativeArgs object

required
server ServerArgs

the server options as a ServerArgs object (default is None)

None
notifier NotifierArgs

the notifier options as a NotifierArgs object (default is None)

None

Returns:

Type Description

a dict of information about the download

Source code in ckanext/versioned_datastore/logic/download/action.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@action(schema.vds_download_queue(), helptext.vds_download_queue)
def vds_download_queue(
    context,
    query: QueryArgs,
    file: DerivativeArgs,
    server: ServerArgs = None,
    notifier: NotifierArgs = None,
):
    """
    Queues a download and returns information about the job and status.

    :param context: the CKAN action context
    :param query: the query as a QueryArgs object
    :param file: the file options as a DerivativeArgs object
    :param server: the server options as a ServerArgs object (default is None)
    :param notifier: the notifier options as a NotifierArgs object (default is None)
    :returns: a dict of information about the download
    """
    server = server or ServerArgs(**ServerArgs.defaults)
    notifier = notifier or NotifierArgs(**NotifierArgs.defaults)

    validate_notifier_args(notifier.type, notifier.type_args)

    if server.custom_filename:
        # check if admin
        try:
            toolkit.check_access('vds_custom_download_filename', context)
        except toolkit.NotAuthorized:
            server.custom_filename = None

    download_runner = DownloadRunManager(
        query_args=query,
        derivative_args=file,
        server_args=server,
        notifier_args=notifier,
    )

    job = toolkit.enqueue_job(
        download_runner.run,
        queue='download',
        title=download_runner.request.created.strftime('%Y-%m-%d %H:%M:%S'),
        rq_kwargs={'timeout': '24h'},
    )

    return {
        'queued_at': job.enqueued_at.isoformat(),
        'job_id': job.id,
        'download_id': download_runner.request.id,
        'status_json': toolkit.url_for(
            'datastore_status.download_status_json',
            download_id=download_runner.request.id,
            qualified=True,
        ),
        'status_html': toolkit.url_for(
            'datastore_status.download_status',
            download_id=download_runner.request.id,
            qualified=True,
        ),
    }

vds_download_regenerate(context, download_id, server=None, notifier=None)

Regenerates a download.

Parameters:

Name Type Description Default
context

the CKAN action context

required
download_id

the download ID

required
server ServerArgs

the server options as a ServerArgs object (default is None)

None
notifier NotifierArgs

the notifier options as a NotifierArgs object (default is None)

None

Returns:

Type Description

a dict of information about the download

Source code in ckanext/versioned_datastore/logic/download/action.py
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@action(schema.vds_download_regenerate(), helptext.vds_download_regenerate)
def vds_download_regenerate(
    context,
    download_id,
    server: ServerArgs = None,
    notifier: NotifierArgs = None,
):
    """
    Regenerates a download.

    :param context: the CKAN action context
    :param download_id: the download ID
    :param server: the server options as a ServerArgs object (default is None)
    :param notifier: the notifier options as a NotifierArgs object (default is None)
    :returns: a dict of information about the download
    """
    # find the download request first
    original_request = DownloadRequest.get(download_id)
    if original_request is None:
        raise toolkit.ObjectNotFound(f'Download "{download_id}" cannot be found.')

    server_args = ServerArgs.defaults.copy()
    if original_request.server_args is not None:
        server_args.update(**original_request.server_args)
    server = server or ServerArgs(**server_args)

    notifier = notifier or NotifierArgs(**NotifierArgs.defaults)

    query = QueryArgs(
        query=original_request.core_record.query,
        query_version=original_request.core_record.query_version,
        resource_ids=original_request.core_record.get_resource_ids(),
        version=original_request.core_record.get_version(),
    )

    file = DerivativeArgs(
        format=original_request.derivative_record.format,
        **original_request.derivative_record.options,
    )

    return vds_download_queue(context, query, file, server, notifier)