Keep two task services in step, e.g. a JSON file used offline (the local
service) and a CalDAV calendar (the remote one), with synchronize.
Tasks are matched by their :uid. What changed on each side since the last sync is found by comparing it with the base: each task as it was when the two sides last agreed, along with each side's :etag for it where the provider has one. A task's :url and :etag are the provider's, not part of its content, and aren't copied from one side to the other.
The base belongs to the pair of services, so synchronize takes it and
returns the new one, and the app keeps it wherever it likes, written out
with serialize-base and read back with parse-base.
Failures throw an ex-info whose data has a :type of:
::invalid-options The options map isn't valid ::wrong-base The base was made for a different pair of services ::invalid-base The base can't be parsed
Keep two task services in step, e.g. a JSON file used offline (the local service) and a CalDAV calendar (the remote one), with `synchronize`. Tasks are matched by their :uid. What changed on each side since the last sync is found by comparing it with the base: each task as it was when the two sides last agreed, along with each side's :etag for it where the provider has one. A task's :url and :etag are the provider's, not part of its content, and aren't copied from one side to the other. The base belongs to the pair of services, so `synchronize` takes it and returns the new one, and the app keeps it wherever it likes, written out with `serialize-base` and read back with `parse-base`. Failures throw an ex-info whose data has a :type of: ::invalid-options The options map isn't valid ::wrong-base The base was made for a different pair of services ::invalid-base The base can't be parsed
(local-wins _conflict)Resolves a conflict in favor of the local side.
Resolves a conflict in favor of the local side.
(parse-base s)Reads a base written by serialize-base.
Reads a base written by `serialize-base`.
(remote-wins _conflict)Resolves a conflict in favor of the remote side. The default.
Resolves a conflict in favor of the remote side. The default.
(serialize-base {:keys [local-id remote-id tasks]})The base as a JSON string, which parse-base reads back unchanged.
The base as a JSON string, which `parse-base` reads back unchanged.
(synchronize
local
remote
{:keys [base resolve dry-run?] :or {resolve remote-wins} :as options})Brings the local and remote services into line: each task created, updated or deleted on one side since the last sync is created, updated or deleted on the other. Returns a map of:
:summary What was done: :pulled Tasks saved to the local side, as a map of :created, :updated and :deleted :pushed Likewise for the remote side :conflicts The tasks changed on both sides since the last sync, each a map of its :uid, its :base, :local and :remote content (nil where it was deleted), and its :resolution: :local, :remote, :merged (with the :merged task) or :unresolved :failed The operations that threw, each a map of the :operation (e.g. :push-update), the :task and the :error :base The base for the next sync, for the app to keep
Options:
:local-id Required. A string identifying the local service, e.g. the
file's path
:remote-id Required. A string identifying the remote service, e.g. the
calendar's URL
:base The base the last sync returned, or nil for the first sync,
when every task is new on its side. A base made for other
ids is refused with a ::wrong-base, since it would make the
tasks missing on one side look deleted there
:resolve Settles a conflict: given its map of :uid, :base, :local and
:remote, returns :local or :remote for the side whose content
wins, a task map to save to both, or nil to leave the
conflict unresolved (both sides as they are) until a later
sync. Defaults to remote-wins
:dry-run? When true, returns the summary of what would be done, with
nothing :failed, and the base unchanged, without saving
anything
Both sides are listed in full every time. Creates are carried out before updates and updates before deletes. When an operation fails, the uid's base entry is left as it was, so that the next sync tries again; the base records only what succeeded.
The app must not save tasks through either service, or run another sync of the same pair, while a sync is running (e.g. by syncing and saving from the same agent or under the same lock), or a change can be lost.
Brings the local and remote services into line: each task created,
updated or deleted on one side since the last sync is created, updated or
deleted on the other. Returns a map of:
:summary What was done:
:pulled Tasks saved to the local side, as a map of
:created, :updated and :deleted
:pushed Likewise for the remote side
:conflicts The tasks changed on both sides since the last
sync, each a map of its :uid, its :base, :local
and :remote content (nil where it was deleted),
and its :resolution: :local, :remote, :merged
(with the :merged task) or :unresolved
:failed The operations that threw, each a map of the
:operation (e.g. :push-update), the :task and
the :error
:base The base for the next sync, for the app to keep
Options:
:local-id Required. A string identifying the local service, e.g. the
file's path
:remote-id Required. A string identifying the remote service, e.g. the
calendar's URL
:base The base the last sync returned, or nil for the first sync,
when every task is new on its side. A base made for other
ids is refused with a ::wrong-base, since it would make the
tasks missing on one side look deleted there
:resolve Settles a conflict: given its map of :uid, :base, :local and
:remote, returns :local or :remote for the side whose content
wins, a task map to save to both, or nil to leave the
conflict unresolved (both sides as they are) until a later
sync. Defaults to `remote-wins`
:dry-run? When true, returns the summary of what would be done, with
nothing :failed, and the base unchanged, without saving
anything
Both sides are listed in full every time. Creates are carried out before
updates and updates before deletes. When an operation fails, the uid's
base entry is left as it was, so that the next sync tries again; the base
records only what succeeded.
The app must not save tasks through either service, or run another sync
of the same pair, while a sync is running (e.g. by syncing and saving
from the same agent or under the same lock), or a change can be lost.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |