Repository: ckan/ckan

Issue:
Process completed but unable to post to result_url
### CKAN Version if known (or site URL)
version 2.8.1

### Please describe the expected behaviour
I install ckan with docker, and everything works fine but when I add a resource in datastore it does not work I get this error Process completed but unable to post to result_url

### Please describe the actual behaviour


### What steps can be taken to reproduce the issue? 



Discussion:
This error means that the DataPusher finished its job (ie the data is on the DataStore) but it could not ping back to CKAN via HTTP to update the status. This generally happens because the CKAN host (as defined in `ckan.site_url` is not accessible, in this case from the DataPusher container.

One workaround is to add an entry to your /etc/hosts file (something like `127.0.0.1   ckan-dev` and use that in your `ckan.site_url` setting.

Resolving patch:
diff --git a/ckanext/datapusher/logic/action.py b/ckanext/datapusher/logic/action.py
--- a/ckanext/datapusher/logic/action.py
+++ b/ckanext/datapusher/logic/action.py
@@ -62,7 +62,14 @@ def datapusher_submit(context, data_dict):
     datapusher_url = config.get('ckan.datapusher.url')
 
     site_url = h.url_for('/', qualified=True)
-    callback_url = h.url_for('/api/3/action/datapusher_hook', qualified=True)
+
+    callback_url_base = config.get('ckan.datapusher.callback_url_base')
+    if callback_url_base:
+        callback_url = urlparse.urljoin(
+            callback_url_base.rstrip('/'), '/api/3/action/datapusher_hook')
+    else:
+        callback_url = h.url_for(
+            '/api/3/action/datapusher_hook', qualified=True)
 
     user = p.toolkit.get_action('user_show')(context, {'id': context['user']})
 


Test patch:
diff --git a/ckanext/datapusher/tests/test.py b/ckanext/datapusher/tests/test.py
--- a/ckanext/datapusher/tests/test.py
+++ b/ckanext/datapusher/tests/test.py
@@ -11,6 +11,7 @@
 import ckanext.datastore.backend.postgres as db
 import responses
 import nose
+from nose.tools import assert_equals
 import sqlalchemy.orm as orm
 from ckan.common import config
 from ckanext.datastore.tests.helpers import rebuild_all_dbs, set_url_type
@@ -232,3 +233,33 @@ def test_datapusher_hook_no_resource_id_in_metadata(self):
 
         self.app.post('/api/action/datapusher_hook', params=postparams,
                       status=409)
+
+    @responses.activate
+    @helpers.change_config(
+        'ckan.datapusher.callback_url_base', 'https://ckan.example.com')
+    @helpers.change_config(
+        'ckan.datapusher.url', 'http://datapusher.ckan.org')
+    def test_custom_callback_url_base(self):
+
+        package = model.Package.get('annakarenina')
+        resource = package.resources[0]
+
+        responses.add(
+            responses.POST,
+            'http://datapusher.ckan.org/job',
+            content_type='application/json',
+            body=json.dumps({'job_id': 'foo', 'job_key': 'barloco'})
+        )
+        responses.add_passthru(config['solr_url'])
+
+        tests.call_action_api(
+            self.app, 'datapusher_submit', apikey=self.sysadmin_user.apikey,
+            resource_id=resource.id,
+            ignore_hash=True
+        )
+
+        data = json.loads(responses.calls[-1].request.body)
+        assert_equals(
+            data['result_url'],
+            'https://ckan.example.com/api/3/action/datapusher_hook'
+        )