{"id":15288042,"url":"https://github.com/recruitee/existence","last_synced_at":"2025-04-13T06:32:06.411Z","repository":{"id":37977761,"uuid":"455169881","full_name":"Recruitee/existence","owner":"Recruitee","description":"Asynchronous dependency health checks library.","archived":false,"fork":false,"pushed_at":"2023-01-05T15:36:32.000Z","size":72,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-04-23T17:33:55.294Z","etag":null,"topics":["elixir","health-check","phoenix"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Recruitee.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-03T13:10:57.000Z","updated_at":"2023-03-22T02:17:55.000Z","dependencies_parsed_at":"2023-02-04T07:01:11.610Z","dependency_job_id":null,"html_url":"https://github.com/Recruitee/existence","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Recruitee%2Fexistence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Recruitee%2Fexistence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Recruitee%2Fexistence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Recruitee%2Fexistence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Recruitee","download_url":"https://codeload.github.com/Recruitee/existence/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248674659,"owners_count":21143760,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","health-check","phoenix"],"created_at":"2024-09-30T15:43:55.251Z","updated_at":"2025-04-13T06:32:06.046Z","avatar_url":"https://github.com/Recruitee.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Existence\n\n[![Hex Version](https://img.shields.io/hexpm/v/existence)](https://hex.pm/packages/existence)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen)](https://hexdocs.pm/existence)\n[![CI](https://github.com/Recruitee/existence/workflows/CI/badge.svg)](https://github.com/Recruitee/existence/actions/workflows/ci.yml)\n\nAsynchronous dependency health checks library.\n\n## Features\n* User defined dependencies health-checks with flexible settings, including configurable\n  health-check callback function timeout, startup delay and initial check state.\n* `Existence.Plug` module providing customizable response for a http health-check endpoint.\n* Support for multiple `Existence` instances and associated health-checks endpoints\n  (example use case: separate Kubernetes readiness and liveness http probes).\n* Dependencies health-checks states are cached and accessed using a dedicated ETS table per\n  `Existence` instance, which means practically unlimited requests per second processing capacity\n  without putting unnecessary load on a health-checked dependency.\n\n## Installation\nAdd `Existence` library to your application `mix.exs` file:\n```elixir\n# mix.exs\ndef deps do\n  [\n    {:existence, \"~\u003e 0.3.1\"}\n  ]\nend\n```\n\n## Usage\nDefine dependencies checks callback functions MFA's and start `Existence` child with your application\nsupervisor:\n```elixir\n# lib/my_app/application.ex\ndefmodule MyApp.Application do\n  use Application\n\n  def start(_type, _args) do\n    health_checks = [\n      check_postgres: %{mfa: {MyApp.Checks, :check_postgres, []}}\n    ]\n\n    children = [{Existence, checks: health_checks}]\n\n    opts = [strategy: :one_for_one, name: MyApp.Supervisor]\n    Supervisor.start_link(children, opts)\n  end\nend\n```\n\nDeclare your dependencies checks callback functions, in our example case PostgreSQL health-check:\n```elixir\n# lib/my_app/checks.ex\ndefmodule MyApp.Checks do\n  def check_postgres() do\n    \"SELECT 1;\"\n    |\u003e MyApp.Repo.query()\n    |\u003e case do\n      {:ok, %Postgrex.Result{num_rows: 1, rows: [[1]]}} -\u003e :ok\n      _ -\u003e :error\n    end\n  end\nend\n```\n\nDependency health-check function `check_postgres/0` will be spawned asynchronously by default every\n30 seconds, checking if PostgreSQL instance associated with `MyApp.Repo` is healthy.\n`check_postgres/0` results will be cached in the ETS table used further to provide responses to user\nrequests. If `/healthcheck` endpoint requests are issued thousands of times per second, they do not\nhit and overload PostgreSQL, instead cached results from ETS are returned.\n\nCurrent overall health-check state can be examined with `get_state/1`:\n```elixir\niex\u003e Existence.get_state()\n:ok\n```\n\nDependencies health-checks states can be examined with `get_checks/1`:\n```elixir\niex\u003e Existence.get_checks()\n[check_postgres: :ok]\n```\n\nLibrary provides Plug module generating responses to the `/healthcheck` endpoint requests.\nExample `Existence.Plug` usage with `Plug.Router.forward/2`:\n```elixir\ndefmodule MyAppWeb.Router do\n  use MyAppWeb, :router\n\n  forward(\"/healthcheck\", Existence.Plug)\nend\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecruitee%2Fexistence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frecruitee%2Fexistence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecruitee%2Fexistence/lists"}