How can I cancel an ongoing request in [GMSPlacesClient autocompleteQuery]? - ios8

I would like to add autocomplete feature to my app.
My idea is to use autocompleteQuery:bounds:filter:callback from GMSPlacesClient class.
While user is typing, I would like to call that method, but I guess if I send several requests, I could receive responses out of order. For that reason I would like to cancel the current one, but I don't see a way.
Maybe it is implemented internally, I don't know.
Any help or suggestion? Thanks a lot.
I realised responses could come out of order. I created a small sample with a textfield and one table.
I sent a request every time user taps a letter and the results say that there is no automatic request cancelation or order.
2015-11-13 15:16:14.668 TestGooglePlaces[5233:60b] u
2015-11-13 15:16:15.550 TestGooglePlaces[5233:60b] ut
2015-11-13 15:16:15.700 TestGooglePlaces[5233:60b] uto
2015-11-13 15:16:15.967 TestGooglePlaces[5233:60b] utop
2015-11-13 15:16:16.552 TestGooglePlaces[5233:60b] utopi
2015-11-13 15:16:23.035 TestGooglePlaces[5233:60b] Results for u
2015-11-13 15:16:23.079 TestGooglePlaces[5233:60b] Results for utop
2015-11-13 15:16:23.087 TestGooglePlaces[5233:60b] Results for utopi
2015-11-13 15:16:23.093 TestGooglePlaces[5233:60b] Results for ut
2015-11-13 15:16:23.155 TestGooglePlaces[5233:60b] Results for uto
How can I fix that problem? The only idea I have is to use the REST web service and cancel the ongoing requests manually.

We on the Places API for iOS team are aware of this problem and are working on it. In the next release of the SDK we'll have a class which takes care of managing these requests and returning them in the correct order.
In the meantime, you can manage these requests by keeping track of the order that the requests came in and ignoring responses if they're too old:
#implementation YourClass {
NSUInteger _sequenceNumber;
__block NSUInteger _mostRecentResponseNumber;
}
- (void)autocompleteQuery:(NSString *)query {
NSUInteger thisSequenceNumber = ++_sequenceNumber;
[_placesClient autocompleteQuery:query
bounds:nil
filter:nil
callback:^(NSArray * _Nullable results, NSError * _Nullable error) {
if (thisSequenceNumber <= _mostRecentResponseNumber) {
return;
}
_mostRecentResponseNumber = thisSequenceNumber;
// process results here
}];
}
Not the nicest, but it should work until we release a better way of doing this :)

Related

Get status of a task Elasticsearch for a long running update query

Assuming I have a long running update query where I am updating ~200k to 500k, perhaps even more.Why I need to update so many documents is beyond the scope of the question.
Since the client times out (I use the official ES python client), I would like to have a way to check what the status of the bulk update request is, without having to use enormous timeout values.
For a short request, the response of the request can be used, is there a way I can get the response of the request as well or if I can specify a name or id to a request so as to reference it later.
For a request which is running : I can use the tasks API to get the information.
But for other statuses - completed / failed, how do I get it.
If I try to access a task which is already completed, I get resource not found .
P.S. I am using update_by_query for the update
With the task id you can look up the task directly:
GET /_tasks/taskId:1
The advantage of this API is that it integrates with
wait_for_completion=false to transparently return the status of
completed tasks. If the task is completed and
wait_for_completion=false was set on it them it’ll come back with a
results or an error field. The cost of this feature is the document
that wait_for_completion=false creates at .tasks/task/${taskId}. It is
up to you to delete that document.
From here https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html#docs-update-by-query-task-api
My use case went like this, I needed to do an update_by_query and I used painless as the script language. At first I did a reindex (when testing). Then I tried using the update_by_query functionality (they resemble each other a lot). I did a request to the task api (the operation hasn't finished of course) and I saw the task being executed. When it finished I did a query and the data of the fields that I was manipulating had disappeared. The script worked since I used the same script for the reindex api and everything went as it should have. I didn't investigate further because of lack of time, but... yeah, test thoroughly...
I feel GET /_tasks/taskId:1 confusing to understand. It should be
GET http://localhost:9200/_tasks/taskId
A taskId looks something like this NCvmGYS-RsW2X8JxEYumgA:1204320.
Here is my trivial explanation related to this topic.
To check a task, you need to know its taskId.
A task id is a string that consists of node_id, a colon, and a task_sequence_number. An example is taskId = NCvmGYS-RsW2X8JxEYumgA:1204320 where node_id = NCvmGYS-RsW2X8JxEYumgA and task_sequence_number = 1204320. Some people including myself thought taskId = 1204320, but that's not the way how the elasticsearch codebase developers understand it at this moment.
A taskId can be found in two ways.
wait_for_deletion = false. When sending a request to ES, with this parameter, the response will be {"task" : "NCvmGYS-RsW2X8JxEYumgA:1204320"}. Then, you can check a status of that task like this GET http://localhost:9200/_tasks/NCvmGYS-RsW2X8JxEYumgA:1204320
GET http://localhost:9200/_tasks?detailed=false&actions=*/delete/byquery. This example will return you the status of all tasks with action = delete_by_query. If you know there is only one task running on ES, you can find your taskId from the response of all running tasks.
After you know the taskId, you can get the status of a task with this.
GET /_tasks/taskId
Notice you can only check the status of a task when the task is running, or a task is generated with wait_for_deletion == false.
More trivial explanation, wait_for_deletion by default is true. Based on my understanding, tasks with wait_for_deletion = true are "in-memory" only. You can still check the status of a task while it's running. But it's completely gone after it is completed/canceled. Meaning checking the status will return you a 'resouce_not_found_exception'. Tasks with wait_for_deletion = false will be stored in an ES system index .task. You can still check it's status after it finishes. However, you might want to delete this task document from .task index after you are done with it to save some space. The deletion request looks like this
http://localhost:9200/.tasks/task/NCvmGYS-RsW2X8JxEYumgA:1204320
You will receive resouce_not_found_exception if a taskId is not present. (for example, you deleted some task twice, or you are deleting an in-memory task, whose wait_for_deletetion == true).
About this confusing taskId thing, I made a pull request https://github.com/elastic/elasticsearch/pull/31122 to help clarify the Elasticsearch document. Unfortunately, they rejected it. Ugh.

Firebase serverTimeOffset and Firebase.ServerValue.TIMESTAMP differences

Context
I have multiple servers listening to a specific collection (/items). Each of them use NTS for time calibration and the ".info/serverTimeOffset" to measure the expected time difference with Firebase. It is consistently around 20ms.
I have many clients pushing items to the collection with the specific field:
{
...
created: Firebase.database.ServerValue.TIMESTAMP
}
What is expected:
When the server receives the item from Firebase and subtracts the item.created with the Firebase expected time (Date.now() + offset), this value should be positive and probably around 10ms (time for the item to be sent from Firebase to the server).
What is happening:
When the server receives the items, the item.created field is superior to the Firebase expected time. Like it was created in the future. Usually the difference is around -5ms
Question:
What is the Firebase.database.ServerValue.TIMESTAMP set to ? and how is it related to the ".info/serverTimeOffset" ?
The 27th September 2016 at 1am UTC, that difference jumped from -5ms to around -5000ms like a kind of re-calibration happened (it lasted until I reset the .info/serverTimeOffset) Did someone experienced something similar?

Asana - How to query for tasks completed between dates?

I am trying to get a collection of tasks that are in a specific team and completed between certain dates such as last month. I see in the API docs that there is a task.find_all but that seems to give everything after a certain completion date and then it even gives incomplete tasks.
From ruby-asana docs:
.find_all(client, assignee: nil, workspace: nil, completed_since: nil, >modified_since: nil, per_page: 20, options: {}) ⇒ Object
Returns the compact task records for some filtered set of tasks.
From Asana API:
completed_since '2012-02-22T02:06:58.158Z'
Only return tasks that are either incomplete or that have been completed since this time.
It seems like I would need to get tasks completed after a certain date and then iterate and select those that have a completion date before my end date and are completed.
Is there a better way?
Apologies for the delayed answer, but yes, that is currently the way to do it.

remove hadoop info streaming.PipeMapRed and others

When I run hadoop, I get many info massages. So I want to remove unuseful, such as INFO streaming.PipeMapRed, INFO mapred.MapTask etc. And retain the most important - INFO mapreduce.Job.
So how to do it?enter image description here
There is an Interface in org.apache.hadoop.mapred called Reporter which provides report progress and update counters, status information etc. If you have access to the code, You can eliminate INFO messages and report imporant ones with setStatus method.

Apache Spark DAGScheduler Missing Parents for Stage

When running my iterative program on Apache Spark I occasionally get the message:
INFO scheduler.DAGScheduler: Missing parents for Stage 4443: List(Stage 4441, Stage 4442)
I gather it means it needs to compute the parent RDD - but I am not 100% sure. I don't just get one of these, I end up with 100's if not thousands of them at a time - it completely slows down my programme and another iteration does not complete for 10-15 minutes (they usually take 4-10 seconds).
I cache the main RDD on each iteration, using StorageLevel.MEMORY_AND_DISK_SER. The next iteration uses this RDD. The lineage of the RDD therefore gets very large hence the need for caching. However, if I am caching (and spilling to disk) how can a parent be lost?
I quote Imran Rashid from Cloudera:
It's normal for stages to get skipped if they are shuffle map stages, which get read multiple times. Eg., here's a little example program I wrote earlier to demonstrate this: "d3" doesn't need to be re-shuffled since each time its read w/ the same partitioner. So skipping stages in this way is a good thing:
val partitioner = new org.apache.spark.HashPartitioner(10)
val d3 = sc.parallelize(1 to 100).map { x => (x % 10) -> x}.partitionBy(partitioner)
(0 until 5).foreach { idx =>
val otherData = sc.parallelize(1 to (idx * 100)).map{ x => (x % 10) -> x}.partitionBy(partitioner)
println(idx + " ---> " + otherData.join(d3).count())
}
If you run this, f you look in the UI you'd see that all jobs except for the first one have one stage that is skipped. You will also see this in the log:
15/06/08 10:52:37 INFO DAGScheduler: Parents of final stage: List(Stage 12, Stage 13)
15/06/08 10:52:37 INFO DAGScheduler: Missing parents: List(Stage 13)
Admittedly that is not very clear, but that is sort of indicating to you that the DAGScheduler first created stage 12 as a necessary step, and then later on changed its mind by realizing that everything it needed for stage 12 already existed, so there was nothing to do.
See the following for the email source:
http://apache-spark-developers-list.1001551.n3.nabble.com/

Resources