From 2589e2d417439642c1d0e58771be3cc5628c3b49 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 19 Nov 2015 10:54:28 +0000 Subject: [PATCH] Gracefully return when an op has already been submitted It is not a fatal error if an op has already been submitted. We just need to send an ack back to the client that submitted it and continue. If we detect a duplicate op, set dup: true on the op and pass it back to real-time for distributing. The dup: true flag will ensure it only gets acknowledged to the submitting client, not everyone. --- .../app/coffee/ShareJsUpdateManager.coffee | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/services/document-updater/app/coffee/ShareJsUpdateManager.coffee b/services/document-updater/app/coffee/ShareJsUpdateManager.coffee index 83786cbb96..20de2d1dfd 100644 --- a/services/document-updater/app/coffee/ShareJsUpdateManager.coffee +++ b/services/document-updater/app/coffee/ShareJsUpdateManager.coffee @@ -32,7 +32,14 @@ module.exports = ShareJsUpdateManager = for update in updates do (update) => jobs.push (callback) => - model.applyOp doc_key, update, callback + model.applyOp doc_key, update, (error) -> + if error == "Op already submitted" + logger.warn {project_id, doc_id, update}, "op has already been submitted" + update.dup = true + ShareJsUpdateManager._sendOp(project_id, doc_id, update) + callback() + else + callback(error) async.series jobs, (error) => logger.log project_id: project_id, doc_id: doc_id, error: error, "applied updates" @@ -49,11 +56,15 @@ module.exports = ShareJsUpdateManager = _listenForOps: (model) -> model.on "applyOp", (doc_key, opData) -> [project_id, doc_id] = Keys.splitProjectIdAndDocId(doc_key) - data = JSON.stringify - project_id: project_id - doc_id: doc_id - op: opData - rclient.publish "applied-ops", data + ShareJsUpdateManager._sendOp(project_id, doc_id, opData) + + _sendOp: (project_id, doc_id, opData) -> + data = + project_id: project_id + doc_id: doc_id + op: opData + data = JSON.stringify data + rclient.publish "applied-ops", data _sendError: (project_id, doc_id, error) -> data = JSON.stringify