Skip to content

Commit

Permalink
[#938] Save the status of the datapusher task
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Aug 7, 2013
1 parent c5ee465 commit 1b20a14
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ckanext/datastore/logic/action.py
@@ -1,6 +1,7 @@
import logging
import json
import urlparse
import datetime

import pylons
import requests
Expand Down Expand Up @@ -442,6 +443,10 @@ def datapusher_submit(context, data_dict):
:type set_url_to_dump: boolean
'''

if 'id' in data_dict:
data_dict['resource_id'] = data_dict['id']
res_id = _get_or_bust(data_dict, 'resource_id')

# ToDo: add task
# ToDo: handle set_url_to_dump

Expand All @@ -456,10 +461,20 @@ def datapusher_submit(context, data_dict):
'job_type': 'push_to_datastore',
'metadata': {
'ckan_url': pylons.config['ckan.site_url'],
'resource_id': data_dict['resource_id']
'resource_id': res_id
}
}))

p.toolkit.get_action('task_status_update')(context, {
'entity_id': res_id,
'entity_type': 'resource',
'task_type': 'datapusher',
'key': 'datapusher',
'value': datapusher_url,
'last_updated': str(datetime.datetime.now()),
'state': 'pending',
})


def _resource_exists(context, data_dict):
# Returns true if the resource exists in CKAN and in the datastore
Expand Down
28 changes: 28 additions & 0 deletions ckanext/datastore/tests/test_create.py
Expand Up @@ -591,6 +591,34 @@ def test_cant_provide_resource_and_resource_id(self):

assert res_dict['error']['__type'] == 'Validation Error'

@httpretty.activate
def test_send_datapusher_creates_task(self):
httpretty.HTTPretty.register_uri(
httpretty.HTTPretty.POST,
'http://datapusher.ckan.org/job',
content_type='application/json',
body=json.dumps({'job_id': 'foo', 'job_key': 'bar'}))

package = model.Package.get('annakarenina')
resource = package.resources[0]

context = {
'ignore_auth': True,
'user': self.sysadmin_user.name
}

p.toolkit.get_action('datapusher_submit')(context, {
'resource_id': resource.id
})

task = p.toolkit.get_action('task_status_show')(context, {
'entity_id': resource.id,
'task_type': 'datapusher',
'key': 'datapusher'
})

assert task['state'] == 'pending', task

def test_guess_types(self):
resource = model.Package.get('annakarenina').resources[1]

Expand Down

0 comments on commit 1b20a14

Please sign in to comment.