taskwarrior icon indicating copy to clipboard operation
taskwarrior copied to clipboard

Tasks introduced via 'sync' should trigger hooks

Open johl opened this issue 6 years ago • 11 comments

When using several instances of Taskwarrior on different devices (e.g. on a mobile phone with Android and on a computer), only locally added tasks trigger the on-modify hook.

Syncing means that tasks can be added from other sources and on-modify should be triggered when a new task comes in from a remote source. I see the exception made for sync to be counter-intuitive and cannot see a good reason for it.

johl avatar Apr 16 '19 09:04 johl

Sorry, disagree. Tasks arriving via sync have already passed through any on-modify hook on the CLI, and shouldn't be modified again.

pbeckingham avatar Apr 16 '19 12:04 pbeckingham

This would be true if the only possibility to add tasks would be to add them with the CLI or on a system that has hooks. This is not the case.

johl avatar Apr 16 '19 13:04 johl

I was about to report this same issue.

I just started using taskwarrior+timewarrior (with the onModify hook to track time) yesterday and set up sync, also installing the android app. If I start/stop tasks in the android app, and sync both devices, my desktop computer hooks don't get executed, so timewarrior doesn't update time tracking. This is unfortunate and I don't see any workaround.

sherwoodinc avatar Dec 16 '20 12:12 sherwoodinc

This is a pickle, because while this is a valid use case (i.e. a mobile TW client might not have a way of implementing hooks), it also means that the hooks scripts now can run multiple times for any given task (i.e. if the hooks are installed on two clients).

In that case we'd either have to require the hook implementation to be idempotent or implement some mechanism for that ourselves.

tbabej avatar Dec 30 '20 13:12 tbabej

Any news on this?

johl avatar Feb 14 '21 00:02 johl

As things stand, we don't have a good solution for this problem. Maybe a new hook entrypoint, on-sync could help here?

tbabej avatar Feb 14 '21 00:02 tbabej

That would absolutely help. I think that's the best solution.

johl avatar Feb 14 '21 03:02 johl

I "fixed" the issue in my desktop install by forcing on-modify for synced tasks. In my simple workflow it doesn't bring issues.

About the on-sync hook (which sounds good)... Does it mean timewarrior should be hooked both to on-modify and on-sync to work properly in my mobile+desktop setup?

sherwoodinc avatar Feb 14 '21 13:02 sherwoodinc

Correct. You could just create a symlink to the on-modify hook. By doing that however, you should make sure the underlying hook is idempotent (meaning it's fine if it runs on the same task twice), as you can run into the problem where it would be first executed on first client during on-modify event and then again on the second client during on-sync event.

tbabej avatar Feb 14 '21 16:02 tbabej

Related to #1790.

tbabej avatar Feb 14 '21 16:02 tbabej

I think sync and hooks are fundamentally incompatible, since the hooks happen on one replica, and sync is between many replicas.

In practice, I think this is OK -- most people use one or the other. But I can see the opportunity for lots of trouble in an on-sync hook, as if that hook creates any further modifications then those, too, would get sync'd to other replicas, easily causing loops.

djmitche avatar May 27 '24 21:05 djmitche