If I create a one-shot (non-continuous) pull replication task from the REST API will it return immediately? Or will it wait until all the data has been replicated before returning?
traun
October 18, 2016, 2:56pm
2
Do you mean calling the Sync Gateway _replicate endpoint?
http://developer.couchbase.com/documentation/mobile/current/develop/references/sync-gateway/rest-api/index.html#operation--_replicate-post
Assuming that’s what you are asking, it runs synchronously by default:
func (r *Replicator) startOneShotReplication(parameters sgreplicate.ReplicationParameters) (sgreplicate.SGReplication, error) {
replication := sgreplicate.StartOneShotReplication(parameters)
r.addReplication(replication, parameters)
if parameters.Async {
go r.runOneShotReplication(replication, parameters)
return replication, nil
} else {
err := r.runOneShotReplication(replication, parameters)
return replication, err
}
}
and the request will block until the replication has finished.
But there is an undocumented parameter “async” (boolean) that you can add to the JSON which will make it run asynchronously:
type ReplicationConfig struct {
Source string `json:"source"`
Target string `json:"target"`
Continuous bool `json:"continuous"`
CreateTarget bool `json:"create_target"`
DocIds []string `json:"doc_ids"`
Filter string `json:"filter"`
Proxy string `json:"proxy"`
QueryParams interface{} `json:"query_params"`
Cancel bool `json:"cancel"`
Async bool `json:"async"`
ChangesFeedLimit *int `json:"changes_feed_limit"`
ReplicationId string `json:"replication_id"`
}
func (h *handler) readReplicationParametersFromJSON(jsonData []byte) (params sgreplicate.ReplicationParameters, cancel bool, localdb bool, err error) {
var in ReplicationConfig
if err = json.Unmarshal(jsonData, &in); err != nil {
return params, false, localdb, err
}
Thanks, I wan’t it to run synchronously. I just saw an awful lot of logging in xCode after the task had returned and wondered if it was because it was still running.
jens
October 18, 2016, 11:53pm
4
One-shot replications are a synchronous HTTP call, continuous ones are asynchronous (obviously, since otherwise it would never return…)