{"id":15616342,"url":"https://github.com/kbrw/delayed_otp","last_synced_at":"2025-08-22T07:44:34.598Z","repository":{"id":53082445,"uuid":"51703872","full_name":"kbrw/delayed_otp","owner":"kbrw","description":"Delay death of supervisor children or gen_server : for instance Erlang supervisor with exponential backoff restart strategy","archived":false,"fork":false,"pushed_at":"2024-02-22T09:50:00.000Z","size":29,"stargazers_count":25,"open_issues_count":5,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-18T21:54:48.615Z","etag":null,"topics":["erlang","supervisor"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kbrw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-02-14T17:06:23.000Z","updated_at":"2024-12-26T01:06:28.000Z","dependencies_parsed_at":"2024-02-22T10:55:13.665Z","dependency_job_id":null,"html_url":"https://github.com/kbrw/delayed_otp","commit_stats":{"total_commits":19,"total_committers":3,"mean_commits":6.333333333333333,"dds":"0.21052631578947367","last_synced_commit":"b0a128ca08d50ee2aa74a0b84fa27e920254f20b"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/kbrw/delayed_otp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbrw%2Fdelayed_otp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbrw%2Fdelayed_otp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbrw%2Fdelayed_otp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbrw%2Fdelayed_otp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kbrw","download_url":"https://codeload.github.com/kbrw/delayed_otp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbrw%2Fdelayed_otp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271606323,"owners_count":24788970,"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","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["erlang","supervisor"],"created_at":"2024-10-03T07:06:53.545Z","updated_at":"2025-08-22T07:44:34.533Z","avatar_url":"https://github.com/kbrw.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DelayedOTP\n\n`DelayedSup and DelayedServer` are respectively `Supervisor` and `GenServer`\nbut with the capability to delay the death of the child or the server to have a\nbetter supervision restart time control.\n\nWith exactly the same API as `Supervisor`, create a supervisor which allows you\nto control a minimum delay for the supervised children to die.\n\nYou can for instance : \n\n- get an Exponential backoff restarting strategy for children\n- normalized death time for port managed external processes \n\nUseful to manage external service in Elixir supervisors.\n\n## Usage\n\nAll the same as `Supervisor`, but a new option is available: `:delay_fun` which is a\nfunction returning the minimum lifetime of a child in millisecond (child death will be delayed\nif it occurs too soon).\n\nThe signature of `:delay_fun` is: `(child_id :: term, ms_lifetime :: integer, acc :: term) -\u003e {ms_delay_death :: integer, newacc:: term}`\nFirst start accumulator is `nil`.\n\nBelow an example usage with an exponential backoff strategy: (200*2^count) ms\ndelay where the backoff count is reset when previous run lifetime was \u003e 5 secondes.\n\n```Elixir\nimport DelayedSup.Spec\nimport Bitwise\n@reset_backoff_lifetime 5_000\n@init_backoff_delay 200\nDelayedSup.start_link([\n  worker(MyServer1,[]),\n  worker(MyServer2,[])\n], restart_strategy: :one_for_one, \n   delay_fun: fn _id,lifetime,count_or_nil-\u003e\n               count = count_or_nil || 0\n               if lifetime \u003e @reset_backoff_lifetime, \n                 do: {0,0}, \n                 else: {@init_backoff_delay*(1 \u003c\u003c\u003c count),count+1}\n          end)\n```\n\n## How it works\n\nThe created \"supervisor\" creates actually the following supervision tree :\n\n`supervise([child1,child2], strategy: :one_for_one)` =\u003e\n\n```\n+--------------+       +----------+      +---------+\n| Supervisor   +------\u003e+TempServer+-----\u003e+ Child1  |\n+--------------+       +----------+      +---------+\n               |       +----------+      +---------+\n               +------\u003e+TempServer+-----\u003e+ Child2  |\n                       +----------+      +---------+\n```\n\n`TempServer` (actually `DelayedServer`) is an intermediate process\nwhich can delay its death relatively to its linked server.\n\nRestart Counter, and delay computation function are kept into the supervisor\nprocess dictionnary.\n\nThe shutdown strategy (brutal kill or max shutdown duration) is handled by the temp server.\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed as:\n\n  1. Add `delayed_otp` to your list of dependencies in `mix.exs`:\n\n        def deps do\n          [{:delayed_otp, \"~\u003e 0.0.1\"}]\n        end\n\n  2. Ensure `delayed_otp` is started before your application:\n\n        def application do\n          [applications: [:delayed_otp]]\n        end\n\n\n# CONTRIBUTING\n\nHi, and thank you for wanting to contribute.\nPlease refer to the centralized informations available at: https://github.com/kbrw#contributing\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkbrw%2Fdelayed_otp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkbrw%2Fdelayed_otp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkbrw%2Fdelayed_otp/lists"}