Dust (dustlayer v0.1.3)

Copy Markdown View Source

Dust SDK — reactive global map client.

Summary

Functions

Returns the WebSocket URL for Dust's hosted cloud service at dustlayer.io.

Coordinated distributed cache-fill — compute fun once across the fleet and share the result.

Functions

add(store, path, member)

See Dust.SyncEngine.add/3.

add(store, path, member, opts)

See Dust.SyncEngine.add/4.

child_spec(opts)

cloud_url()

Returns the WebSocket URL for Dust's hosted cloud service at dustlayer.io.

Use as the :url option when starting the supervisor against cloud:

{Dust, stores: ["acme/site"], url: Dust.cloud_url(), token: token, cache: ...}

delete(store, path)

See Dust.SyncEngine.delete/2.

delete(store, path, opts)

See Dust.SyncEngine.delete/3.

entry(store, path)

See Dust.SyncEngine.entry/2.

enum(store, pattern)

See Dust.SyncEngine.enum/2.

enum(store, pattern, opts)

See Dust.SyncEngine.enum/3.

get(store, path)

See Dust.SyncEngine.get/2.

get_many(store, paths)

See Dust.SyncEngine.get_many/2.

increment(store, path, delta \\ 1)

See Dust.SyncEngine.increment/3.

increment(store, path, delta, opts)

See Dust.SyncEngine.increment/4.

lease(store, key, opts \\ [])

See Dust.SyncEngine.lease/3.

merge(store, path, map)

See Dust.SyncEngine.merge/3.

merge(store, path, map, opts)

See Dust.SyncEngine.merge/4.

off(store, ref)

See Dust.SyncEngine.off/2.

on(store, pattern, callback, opts \\ [])

See Dust.SyncEngine.on/4.

put(store, path, value)

See Dust.SyncEngine.put/3.

put(store, path, value, opts)

See Dust.SyncEngine.put/4.

put_file(store, path, source_path)

See Dust.SyncEngine.put_file/3.

put_file(store, path, source_path, opts)

See Dust.SyncEngine.put_file/4.

range(store, from, to, opts \\ [])

See Dust.SyncEngine.range/4.

release(store, lease)

See Dust.SyncEngine.release/2.

remove(store, path, member)

See Dust.SyncEngine.remove/3.

remove(store, path, member, opts)

See Dust.SyncEngine.remove/4.

renew(store, lease, opts \\ [])

See Dust.SyncEngine.renew/3.

single_flight(store, key, fun, opts \\ [])

Coordinated distributed cache-fill — compute fun once across the fleet and share the result.

Returns {:ok, %Dust.Flight{}} or {:error, reason}.

fun receives the held %Dust.Lease{} (or nil on the degraded :run_local path) and MUST return:

  • {:publish, value} — store value at key and return it. value must be a small pointer (put the bytes in S3/your DB). Publish a definitive negative (e.g. a genuinely empty result) so the freshness window holds and you don't recompute — classification is domain-specific (an empty page may be definitive; a 404 that will appear later is transient).
  • {:abort, reason} — release the lease, publish nothing, return {:error, reason}. Use this for transient failures so they aren't cached. Prefer {:abort, _} over raising for expected/transient errors: it releases the lease immediately (waiters re-elect at once), whereas a raised fun only frees the lease when lease_ttl expires (the heartbeat dies with the caller). Inside an Oban worker especially, abort cleanly rather than raise.

Options:

  • :fresh?nil (default) = presence mode (key exists ⇒ fresh; for done-forever results). A (value -> boolean) predicate = freshness mode (the value carries its own timestamp; refill when the predicate says so).
  • :lease_ttl — max in-flight fill time before the lease is stealable (default 30s; the lease is heartbeat-renewed while fun runs).
  • :wait_timeout — max a follower waits for the winner (default lease_ttl + 5s).
  • :on_unavailable:run_local (default; run fun uncoordinated, never block — possible duplicate work, coordinated?: false) or :error.
  • :lock_key — the lease key (default a reserved sibling of key).

At-least-once, not exactly-once. fun must be idempotent.

status(store)

See Dust.SyncEngine.status/1.

unsubscribe(store, ref)

See Dust.SyncEngine.off/2.

watch(store, pattern, callback, opts \\ [])

See Dust.SyncEngine.on/4.