summary refs log tree commit diff
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-03-09 17:45:41 +0000
committerKegan Dougal <kegan@matrix.org>2015-03-09 17:45:41 +0000
commit04c9751f24885b974d564b3e5749b7fc9ce01c73 (patch)
treecb62723909589e3ad8e3a1a8a3aaedfb3deb6fac
parentUse event IDs instead of dumping event content in the txns table. (diff)
downloadsynapse-04c9751f24885b974d564b3e5749b7fc9ce01c73.tar.xz
Bug fixes whilst putting it all together
-rw-r--r--synapse/appservice/api.py1
-rw-r--r--synapse/appservice/scheduler.py4
-rw-r--r--synapse/storage/appservice.py9
3 files changed, 8 insertions, 6 deletions
diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py
index c17fb219c5..3acb8867a2 100644
--- a/synapse/appservice/api.py
+++ b/synapse/appservice/api.py
@@ -79,6 +79,7 @@ class ApplicationServiceApi(SimpleHttpClient):
             logger.warning("push_bulk: Missing txn ID sending events to %s",
                            service.url)
             txn_id = str(0)
+        txn_id = str(txn_id)
 
         uri = service.url + ("/transactions/%s" %
                              urllib.quote(txn_id))
diff --git a/synapse/appservice/scheduler.py b/synapse/appservice/scheduler.py
index 068d4bd087..3ee2406463 100644
--- a/synapse/appservice/scheduler.py
+++ b/synapse/appservice/scheduler.py
@@ -175,7 +175,7 @@ class _TransactionController(object):
     @defer.inlineCallbacks
     def _is_service_up(self, service):
         state = yield self.store.get_appservice_state(service)
-        defer.returnValue(state == ApplicationServiceState.UP)
+        defer.returnValue(state == ApplicationServiceState.UP or state is None)
 
 
 class _Recoverer(object):
@@ -208,6 +208,8 @@ class _Recoverer(object):
     def retry(self):
         txn = yield self._get_oldest_txn()
         if txn:
+            logger.info("Retrying transaction %s for service %s",
+                        txn.id, txn.service)
             if txn.send(self.as_api):
                 txn.complete(self.store)
                 # reset the backoff counter and retry immediately
diff --git a/synapse/storage/appservice.py b/synapse/storage/appservice.py
index c3c0a0bd43..ab03106513 100644
--- a/synapse/storage/appservice.py
+++ b/synapse/storage/appservice.py
@@ -337,9 +337,8 @@ class ApplicationServiceStore(SQLBaseStore):
     @defer.inlineCallbacks
     def _populate_cache(self):
         """Populates the ApplicationServiceCache from the database."""
-        sql = ("SELECT * FROM application_services LEFT JOIN "
-               "application_services_regex ON application_services.id = "
-               "application_services_regex.as_id")
+        sql = ("SELECT r.*, a.* FROM application_services AS a LEFT JOIN "
+               "application_services_regex AS r ON a.id = r.as_id")
 
         results = yield self._execute_and_decode(sql)
         services = self._parse_services_dict(results)
@@ -528,7 +527,7 @@ class ApplicationServiceTransactionStore(SQLBaseStore):
             return None
 
         event_ids = json.loads(entry["event_ids"])
-        events = self._get_events_txn(event_ids)
+        events = self._get_events_txn(txn, event_ids)
 
         return AppServiceTransaction(
             service=service, id=entry["txn_id"], events=events
@@ -540,7 +539,7 @@ class ApplicationServiceTransactionStore(SQLBaseStore):
             (service_id,)
         )
         last_txn_id = result.fetchone()
-        if last_txn_id is None:  # no row exists
+        if last_txn_id is None or last_txn_id[0] is None:  # no row exists
             return 0
         else:
             return int(last_txn_id[0])  # select 'last_txn' col