{"id":16656685,"url":"https://github.com/arjan/singleton","last_synced_at":"2025-04-05T02:07:40.242Z","repository":{"id":12596757,"uuid":"72324759","full_name":"arjan/singleton","owner":"arjan","description":"Global, supervised singleton processes for Elixir","archived":false,"fork":false,"pushed_at":"2024-06-20T10:03:27.000Z","size":60,"stargazers_count":108,"open_issues_count":5,"forks_count":21,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T01:05:26.096Z","etag":null,"topics":["elixir-lang"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arjan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-30T04:03:47.000Z","updated_at":"2024-09-09T03:11:16.000Z","dependencies_parsed_at":"2024-12-21T17:05:37.462Z","dependency_job_id":null,"html_url":"https://github.com/arjan/singleton","commit_stats":{"total_commits":49,"total_committers":8,"mean_commits":6.125,"dds":0.6734693877551021,"last_synced_commit":"345debafd53c700681c90086bdb740c77f551514"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjan%2Fsingleton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjan%2Fsingleton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjan%2Fsingleton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjan%2Fsingleton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arjan","download_url":"https://codeload.github.com/arjan/singleton/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276163,"owners_count":20912288,"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-lang"],"created_at":"2024-10-12T09:58:19.228Z","updated_at":"2025-04-05T02:07:35.230Z","avatar_url":"https://github.com/arjan.png","language":"Elixir","readme":"# Singleton\n\n[![Build Status](https://github.com/arjan/singleton/workflows/test/badge.svg)](https://github.com/arjan/singleton)\n[![Module Version](https://img.shields.io/hexpm/v/singleton.svg)](https://hex.pm/packages/singleton)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/singleton/)\n[![Total Download](https://img.shields.io/hexpm/dt/singleton.svg)](https://hex.pm/packages/singleton)\n[![License](https://img.shields.io/hexpm/l/singleton.svg)](https://github.com/arjan/singleton/blob/master/LICENSE)\n[![Last Updated](https://img.shields.io/github/last-commit/arjan/singleton.svg)](https://github.com/arjan/singleton/commits/master)\n\nConvenience wrapper library around Erlang's `global` module to ensure\na single instance of a process is kept running on a cluster of nodes.\n\n## Installation\n\nThe package can be installed as:\n\n1. Add `singleton` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:singleton, \"~\u003e 1.0\"}]\nend\n```\n\n2. Ensure `Singleton.Supervisor` is added to your application's supervision tree:\n\nIf your application includes a supervision tree in `application.ex`, you can simply add `Singleton.Supervisor` to the list of children.\n\n```elixir\nchildren = [\n  # ...,\n  {Singleton.Supervisor, name: MyApp.Singleton}\n]\n\nsupervisor = Supervisor.start_link(children, opts)\n```\n\n## Usage\n\nUse `Singleton.start_child/4` to start a unique GenServer process.\n\n```elixir\nSingleton.start_child(MyApp.Singleton, MyServer, [1], {:myserver, 1})\n```\n\nExecute this command on all nodes. The `MyServer` GenServer is now\nglobally registered under the name `{:global, {:myserver, 1}}`.\n\nAs soon as you connect nodes together, you'll see logger messages\nlike:\n\n    04:56:29.003 [info]  global: Name conflict terminating {MyServer, #PID\u003c12501.68.0\u003e}\n\nWhen you now stop (or disconnect) the node on which the singleton\nprocess runs, you'll see it get started on one of the other nodes.\n\n## Troubleshooting\n\n### More than 3 singleton processes `[info] Application singleton exited: shutdown`\n\nIn case you run more than 3 singleton you'll need to increase the\n`max_restarts` of `DynamicSupervisor`.\n\n```elixir\nconfig :singleton,\n  dynamic_supervisor: [max_restarts: 100]\n```\n\nor add `max_restarts` to your singleton supervisor spec:\n\n```\n  {Singleton.Supervisor, name: MyApp.Singleton, max_restarts: 100}\n```\n","funding_links":[],"categories":["\u003ca name=\"Elixir\"\u003e\u003c/a\u003eElixir"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjan%2Fsingleton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farjan%2Fsingleton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjan%2Fsingleton/lists"}