Relocker.Locker behaviour

A module for acquiring a lock, extending it and releasing the lock.

Summary

Functions

Extend a lock. When successful a new lock struct is returned and that should be used for subsequent calls to this API

Try to acquire a lock. Returns {:ok, %Lock{}} if successful, if not :error is returned

Read lock with name lock_name. Returns {:ok, %Lock{}} if successful

Reset, meant to be used for testing only

Start a locker process

Types

lock_name :: binary | atom

Functions

extend(lock, current_time \\ Relocker.Utils.time())

Extend a lock. When successful a new lock struct is returned and that should be used for subsequent calls to this API.

impl()
lock(name, metadata, lease_time_secs, current_time \\ Relocker.Utils.time())

Try to acquire a lock. Returns {:ok, %Lock{}} if successful, if not :error is returned

read(name, current_time \\ Relocker.Utils.time())

Read lock with name lock_name. Returns {:ok, %Lock{}} if successful.

reset()

Reset, meant to be used for testing only.

start_link(opts)

Start a locker process

unlock(lock, current_time \\ Relocker.Utils.time())

Release a lock.

Callbacks

extend(lock, current_time)

Specs

extend(lock :: Relocker.Lock.t, current_time :: integer) ::
  {:ok, Relocker.Lock.t} |
  :error
lock(name, metadata, lease_time_secs, current_time)

Specs

lock(name :: lock_name, metadata :: any, lease_time_secs :: integer, current_time :: integer) ::
  {:ok, Relocker.Lock.t} |
  :error
read(name, current_time)

Specs

read(name :: lock_name, current_time :: integer) ::
  {:ok, Relocker.Lock.t} |
  :error
reset()

Specs

reset :: :ok | :error
start_link(opts)

Specs

start_link(opts :: []) :: {:ok, pid}
unlock(lock, current_time)

Specs

unlock(lock :: Relocker.Lock.t, current_time :: integer) ::
  :ok |
  :error