A GenServer-backed Ash.DataLayer.
Find a file
dependabot[bot] f556a33ed7
chore(deps-dev): bump git_ops from 2.5.4 to 2.5.5 (#29)
Bumps [git_ops](https://github.com/zachdaniel/git_ops) from 2.5.4 to 2.5.5.
- [Release notes](https://github.com/zachdaniel/git_ops/releases)
- [Changelog](https://github.com/zachdaniel/git_ops/blob/master/CHANGELOG.md)
- [Commits](https://github.com/zachdaniel/git_ops/compare/v2.5.4...v2.5.5)

---
updated-dependencies:
- dependency-name: git_ops
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-19 13:58:30 +13:00
.devcontainer feat: first pass at a genserver backed Ash datalayer. 2022-08-12 16:32:42 +12:00
.github chore: update dependabot.yml 2022-10-27 10:30:26 +13:00
config chore: fix typo in git_ops config. 2022-10-26 09:22:21 +13:00
lib/ash_gen_server feat: resets genserver inactivity with :keep_alive info message 2022-12-12 13:41:20 +09:00
test feat: resets genserver inactivity with :keep_alive info message 2022-12-12 13:41:20 +09:00
.doctor.exs improvement: update CI to staple-actions and get (most) checks passing. 2022-10-26 10:43:45 +13:00
.formatter.exs improvement: update CI to staple-actions and get (most) checks passing. 2022-10-26 10:43:45 +13:00
.gitignore improvement: update CI to staple-actions and get (most) checks passing. 2022-10-26 10:43:45 +13:00
.tool-versions chore: update .tool-versions to latest 2022-10-25 22:46:48 +11:00
CHANGELOG.md chore: release version v0.3.0 2022-12-16 00:57:56 +00:00
LICENSE improvement: update CI to staple-actions and get (most) checks passing. 2022-10-26 10:43:45 +13:00
mix.exs chore: release version v0.3.0 2022-12-16 00:57:56 +00:00
mix.lock chore(deps-dev): bump git_ops from 2.5.4 to 2.5.5 (#29) 2023-01-19 13:58:30 +13:00
README.md chore: release version v0.3.0 2022-12-16 00:57:56 +00:00

AshGenServer

An Ash Datalayer backed by individual GenServers.

This package provides an Ash.DataLayer which stores resources in emphemeral GenServers. The main use-case for this is two fold:

  1. Ability to automatically remove resources after an inactivity timeout.
  2. (Potential) ability to migrate resources across a cluster during deploys to allow access to continue without failure.
  3. before and after hooks for changesets and queries are run within the server process, making registration, etc, possible.

Caveats

  • When a resource using this datalayer is created it spawns an instance of AshGenServer.Server and performs all operations on the data within it. This means that your actions must pay the price of a GenServer.call/3 to read or modify the data.

  • When destroying a resource it's process is terminated and it's internal state is lost.

  • If, for some reason, the AshGenServer.Server process crashes or exits for an abnormal reason the supervisor will restart it with the changeset used by the create action - this means that any updates performed since creation will be lost.

  • Any resource using this data source must have at least one primary key field.

  • Retrieving a resource by primary key is an optimised case, but any other queries will pay the price of having to query every AshGenServer.Server process in sequence.

Installation

If available in Hex, the package can be installed by adding ash_gen_server to your list of dependencies in mix.exs:

def deps do
  [
    {:ash_gen_server, "~> 0.3.0"}
  ]
end

Usage

This package assumes that you have Ash installed and configured. See the Ash documentation for details.

Once installed you can easily define a resource which is backed by a GenServer:

defmodule MyApp.EphemeralResource do
  use Ash.Resource, data_layer: AshGenServer.DataLayer

  attributes do
    uuid_primary_key :id
    attribute :temporary_data, :string
  end
end

Documentation

Documentation for the latest release will be available on hexdocs and for the main branch.

Contributing

  • To contribute updates, fixes or new features please fork and open a pull-request against main.
  • Please use conventional commits - this allows us to dynamically generate the changelog.
  • Feel free to ask any questions on out GitHub discussions page.