Skip to content

Feature request: Auto sync #4017

@odilf

Description

@odilf

Hello, I just started using taskwarrior and I really like!

I think it would be a good idea to have an option to be able to auto-sync tasks. Right now it does say when syncing is needed, but you have to do it manually which seems clunky (i.e., if you forget to do it and you don't have that device available your tasks are stale) and you still have to remember to sync yourself to get changes from other places.

Proposed solution

Add something like a rc.sync.auto option (open to bikeshed) to enable autosync. Maybe it would make sense to also add something like rc.sync.auto.modify-debounce and rc.sync.auto.read-debounce, to be able to configure some debounce timing to not do an unnecessary amount of requests (even though it's generally very little data).

Current alternatives

Right now I'm using a couple of hooks to sync on launch and on modify:

FLAGFILE="/tmp/taskwarrior-needs-sync"
LAST_SYNC="/tmp/taskwarrior-last-sync"
SYNC_INTERVAL=300  # 5 minutes

# Only sync if enough time has passed
time_passed=$(($(date +%s) - $(date -r "$LAST_SYNC" +%s 2>/dev/null || echo 0)))
if [ $time_passed -lt $SYNC_INTERVAL ]; then
  exit 0
fi

/nix/store/h3l2d5mmijwffnmpq3fw598x55d6x6cn-taskwarrior-3.4.1/bin/task rc.hooks=off sync > /dev/null 2>&1
touch "$LAST_SYNC"
exit 0
FLAGFILE="/tmp/taskwarrior-needs-sync"
PIDFILE="/tmp/taskwarrior-sync.pid"

# Echo tasks
read original_task
read added_task
echo "$added_task"

# Mark that we need a sync
touch "$FLAGFILE"

# Exit if sync process already running
if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE") 2>/dev/null; then
  exit 0
fi

# Start background sync process
nohup /nix/store/ndyhaygmwxljqqssbcqz7ir0v5b7cjm9-bash-interactive-5.3p3/bin/bash -c '
  echo $$ > "'"$PIDFILE"'"
  sleep 5
  if [ -f "'"$FLAGFILE"'" ]; then
    rm "'"$FLAGFILE"'"
    '"/nix/store/h3l2d5mmijwffnmpq3fw598x55d6x6cn-taskwarrior-3.4.1/bin/task"' rc.hooks=off sync
  fi
  rm -f "'"$PIDFILE"'"
' > /dev/null 2>&1 </dev/null &

exit 0

but they seems to sometimes make task take waaay too long, it seems you have to use nohup and sometimes they seem to not work . In general I think auto syncing is a desirable feature to have built-in for new users.

I'm not too experienced with C++, but if this is something the team wants I'm willing to give a shot at doing a PR :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions