Attempt to harden and make aw-client more resilient#28
Conversation
|
Seems to work great, only one issue: Not sure how experimental it is, perhaps we should reach out to the developer to find out. |
|
I should add that I'm not certain this behaves the intended way in some circumstances, namely:
There's also an additional issue for future plans (but no deal breaker since it would add significant, hard-to-maintain, complexity to the preexisting solution as well):
|
|
I think I found another option: Edit: shelve could work, but might use a lot of memory and eat a significant chunk of CPU if the queue grows large. The best option still seems to be persist-queue, but it'd take some modifications to work as we want it to. Edit 2: the cons of shelve might not be that bad if we also implement client-side |
Yeah probably. auto_commit=True is set in all the examples in the README so it does seem encouraged there atleast which is odd. |
|
@ErikBjare I came across that your were using persist-queue, just want to answer some your doubt here:
The warning has been removed in v0.3.5 now as the Thanks |
|
@peter-wangxu Awesome! Thanks for reaching out! |
|
@johan-bjareholt This is ready for review, please review meticulously. I'll test it on my machine for the coming days. |
|
Currently testing locally, seems to work. Will have a further look at the code itself later. Still seems to recover incredibly slowly though same as previously, we really need to add the ability to send batches of heartbeats because sending heartbeats and events syncronously over HTTP is incredibly slow even locally. If i queue up heartbeats for 2min it takes another 2min for it to recover those events. Maybe that's the issue why it is delayed on windows, because HTTP requests locally are even slower and doesn't have time to get ahead again after a bit of queueing? Just a guess. |
|
@johan-bjareholt Yeah, batching or premerging would be two options. I started working on a premerge thingy based on this PR, but it quickly got out of hand. Still worth taking a look at just to see all the crazy edgecases when you need to take things like pulsetime into account (not to mention how it breaks many of the guarantees given by persist-queue): #29 |
johan-bjareholt
left a comment
There was a problem hiding this comment.
Not done reviewing yet, might be some more.
Seems good though from a first glance.
| self._registered_buckets = [] # type: List[Bucket] | ||
|
|
||
| self._queue = queue.Queue() | ||
| self._attempt_reconnect_interval = 10 |
There was a problem hiding this comment.
Maybe add this to the config?
There was a problem hiding this comment.
Maybe, but I think it would be a bit overkill.
|
|
||
| def test_pdb(): | ||
| pdb.set_trace() | ||
| """ |
There was a problem hiding this comment.
pdb is pretty handy when testing. You should try it sometime. Removed it now though.
| def add_request(self, endpoint: str, data: dict) -> None: | ||
| """ | ||
| Add a request to the queue. | ||
| NOTE: Only supports heartbeats |
There was a problem hiding this comment.
We used to support both events and heartbeats, what happened to that?
There was a problem hiding this comment.
We never really did in a good way, if we would do so properly it would cause a lot of additional complexity.
| self.queue_file = os.path.join(queued_dir, self.client.name + ".v{}.json".format(self.VERSION)) | ||
|
|
||
| def _create_buckets(self): | ||
| persistqueue_path = os.path.join(queued_dir, self.client.name + ".v{}.persistqueue.sql".format(self.VERSION)) |
There was a problem hiding this comment.
.sql usually means that it contains a sql command rather than a sqlite db, should probably be just .db
| VERSION = 1 # update this whenever the queue-file format changes | ||
|
|
||
| def __init__(self, client, dispatch_interval=0): | ||
| def __init__(self, client: ActivityWatchClient, dispatch_interval: float=0) -> None: |
There was a problem hiding this comment.
Remove default dispatch_interval from class parameter? If it's only for testing aw-client you could just as well just hardcode it.
There was a problem hiding this comment.
dispatch_interval was never used in the class, removed.
| self._create_buckets() | ||
| self.connected = True | ||
| logger.info("Connection to aw-server established") | ||
| logger.info("Connection to aw-server established by {}".format(self.client.client_name)) |
There was a problem hiding this comment.
Why was this change useful? Seems unnecessary to have it print the client name here?
There was a problem hiding this comment.
In the aw-qt log you couldn't tell which client had connected to the server.
There was a problem hiding this comment.
Hm, that sucks. It's a shame that python doesn't print the loggers name in the logmessage by default, it it often very useful.
GStreamer does logging very well with the loggers name, then you can filter them with simple env variables such as GST_DEBUG=mylogger:debug,mylogger2:warn etc.. Very neat.
There was a problem hiding this comment.
I'm pretty sure we could set something similar up in aw-core's setup_logging.
|
@johan-bjareholt Fixed a few things you mentioned, merge? |
TODO
assert isinstance(data, dict)for now (should only happen to people who develop new watchers anyway)task_done())