Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only one instance for each (host+port, client, user) #21

Merged
merged 10 commits into from
Mar 4, 2019

Conversation

johan-bjareholt
Copy link
Member

@johan-bjareholt johan-bjareholt commented Jun 22, 2017

Have not tested on windows

Also updated test_client.py for the new aw-core versions

Doesn't fix ActivityWatch/aw-qt#19, but at least makes it less severe

@ErikBjare
Copy link
Member

ErikBjare commented Jun 22, 2017

What happens if the program is killed by SIGTERM and the __del__ method is never run?

Doesn't look like we inform the user where the lock file is in case it prevents the program from starting.

@johan-bjareholt
Copy link
Member Author

On linux it still works, the lock is released by the kernel.

I have not tested on windows, but should work since it tries to remove the lock file and the lock on the file should be released by the kernel when it is exiting.

Also just relized that you currently cannot run both testing and non-testing at the same time, will fix that.

@ErikBjare
Copy link
Member

I think the lock file should probably be in the cache dir instead of the data dir, or what do you think?

I think the testing vs non-testing should really depend on the module_id + host + port the client tries to connect to, not module_id + testing.

@johan-bjareholt
Copy link
Member Author

Regarding if it should be in the cache dir instead of data dir I agree, will fix.

Regarding testing vs non-testing i currently disagree. Since host+port is fetched from the config file anyway there is little point in doing it like that. If for example you would run the clients as another user the lock files would be in another directory also so that doesn't become an issue. If you would want to report to two servers it would be better to simply utilize aw-sync for that once that's working.

@ErikBjare
Copy link
Member

ErikBjare commented Jun 22, 2017

Strong disagree on removing the ability to send data to multiple hosts from a client.

Just to clarify: Testing will behave the same (pick a special host and port in the config) unless specified. The lockfile name should include host+port instead of a testing tag. Otherwise we would limit a watcher to two running instances in non-testing mode. Why important to avoid this limitation is explaned below.

About sync: The server instances listening to different hosts and ports might not want to sync. Example: one watcher sends to some data collection service (automatic sharing/status/analysis services, studies, etc.) and the other to a local server as the users own copy.

aw-sync's scope is personal, private, sync. Bucket-specific time-interval sync to third party sources is not within the scope of aw-sync (yet?). Would add quite a bit of complexity and require exposing the server, need authentication, etc.

The user might want to "go live" with their data using some service, adding a server sync would increase latency significantly making the reporting happen after 2 syncs. I don't think we should limit aw-sync to be the only syncing solution possible, connecting to multiple servers directly from the client is an excellent alternative for many uses. A personal sync tool with an emphasis on security would get overly complex for cases where third parties are involved and sent unencrypted data.

We should offer host and port keyword parameters on the ActivityWatchClient constructor. This is needed if we want to be able to specify host and port for a single run using cli arguments. So applications managing the watcher can set some settings temporarily without having to deal with the config file (by overriding settings set there). But that's not needed in this PR. We'll do that when the time comes.

@ErikBjare ErikBjare changed the title Only one instance of a client per user Only one instance for each (host+port, client, user) Jun 22, 2017
@ErikBjare
Copy link
Member

But we can merge this for now if you want. Are you done?

from .config import load_config

from .client import ActivityWatchClient
from .client import ActivityWatchClient # noqa
Copy link
Member

@ErikBjare ErikBjare Jun 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is # noqa?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the "Import unused" from landscape.io

…d client constructor parameter for server host+port
@johan-bjareholt
Copy link
Member Author

erb long wall of text

Fair enough. Your example was rather exotic but valid and the host+port solution is more flexible so let's do it that way.

The only issue now would be if someone tried to connect to "localhost:5600" and another client tries at "127.0.0.1:5600" the lock wouldn't work.

@ErikBjare
Copy link
Member

I'll admit it might be a bit exotic. But imo it's such a large gain for such a small effort that it cannot be ignored.

self.server_host = server_host if server_host != None else client_config[configsection]["hostname"]
self.server_port = server_port if server_port != None else client_config[configsection]["port"]

self.instance = SingleInstance("{}@{}:{}".format(self.client_name, self.server_host, self.server_port))
Copy link
Member

@ErikBjare ErikBjare Jun 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that string will be a valid name for a Windows file. Just use dashes or something in place of @ and :.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be fixed.

Copy link
Member

@ErikBjare ErikBjare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That filename thing I commented won't work on Window. Needs a fix.

self.server_host = server_host if server_host != None else client_config[configsection]["hostname"]
self.server_port = server_port if server_port != None else client_config[configsection]["port"]

self.instance = SingleInstance("{}@{}:{}".format(self.client_name, self.server_host, self.server_port))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be fixed.

@ghost ghost assigned ErikBjare Mar 16, 2018
@ghost ghost added the review label Mar 16, 2018
@ErikBjare ErikBjare merged commit 4e270c1 into master Mar 4, 2019
@ghost ghost removed the review label Mar 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When aw-qt crashes, aw-watcher-afk does not shut down
2 participants