THE

Supervisor!

CHEATSHEET

Version 1.0!

def start_link(opts \\ []) do! Supervisor.start_link(__MODULE__, :ok, opts)! end! def init(:ok) do! ! return value! !

RET VAL

CALLBACK

CLIENT

Initialization Returns {:ok, pid}!

supervise(children, options)! !

:ignore!

end!

Define children in the Supervisor Specification supervise(children, options)! EXAMPLE

children = [! supervisor(FooSup,[:bar, :baz], []),! worker(Foo, [:baz, :qux, :quux], []),! ]!

supervisor(module, arg, options)!

DEFAULT OPTIONS

SUPERVISOR

[id: module,! function: :start_link,! restart: :permanent,! shutdown: :infinity,! modules: [module]]!

FooSup.start_link(:bar, :baz) # Expected to be implemented!

WORKER

DEFAULT OPTIONS

worker(module, arg, options)!

This invokes:

[id: module,! function: :start_link,! restart: :permanent,! shutdown: 5000,! modules: [module]]!

Foo.start_link(:baz, :qux, :quux) # Expected to be implemented!

Name Registration Note: Neither worker/3 nor supervise/3 do anything special for name registration. It’ up to you to pass the arguments to GenServer.start_link or Process.register/2 via arg. EXAMPLE

worker(Foo, [:baz, :qux, :quux, name: Foo.Worker], [])!

calls Foo.start_link(:baz, :qux, :quux, name: Foo.Worker)! Then, pass [name: Foo.Worker] (4th parameter) into GenServer.start_link OR Process.register/2. Copyright © Benjamin Tan Wei Hao. Free to use without modification for non-commercial applications.

THE

Supervisor!

CHEATSHEET

Version 1.0!

Name Registration (Optional) Note: I prefer passing in a singly nested list of arguments for GenServers because I can hand them to GenServer.start_link , which invokes the init/1 callback – without modifying the argument. EXAMPLE

worker(Foo, [[:baz, :qux, :quux], name: Foo.Worker], [])!

calls Foo.start_link([:baz, :qux, :quux], name: Foo.Worker)! Then, pass [name: Foo.Worker] (2nd parameter) into GenServer.start_link OR Process.register/2.

OPTIONS

Define children in the Supervisor Specification supervise(children, options)! [id: module,! function: :start_link,! restart: :permanent,! shutdown: 5_000,! modules: [module]]!

1. Determine the restart values: PERMANENT

The child process is always restarted TEMPORARY

The child process is never restarted (not even when the supervisor’s strategy is :rest_for_one or :one_for_all) TRANSIENT

OPTIONS

The child process is restarted only if it terminates abnormally (exit reason other than :normal, :shutdown, {:shutdown, term}!

[id: module,! function: :start_link,! restart: :permanent,! shutdown: 5_000,! modules: [module]]!

2. Determine the shutdown values: BRUTAL KILL

Child process is unconditionally terminated with Process.exit(child, :kill)! INFINITY

If child is a supervisor, this gives the subtree enough time to shutdown. If child is a worker, you can also use this – with care! 5_000

When given an integer, the supervisor terminates the child process using Process.exit(child, :shutdown) and waits for an exist signal within the time (in milliseconds). Otherwise, the child process is brutally killed.!

Copyright © Benjamin Tan Wei Hao. Free to use without modification for non-commercial applications.

THE

Supervisor!

CHEATSHEET

Version 1.0!

Define options in the Supervisor Specification supervise(children, options)! EXAMPLE

options = [! strategy: :one_for_all, max_restarts: 3, max_seconds: 5 ! ]!

1. Decide on the strategy: ONE FOR ONE

If a child process terminates, only that process is restarted. ONE FOR ALL

If a child process terminates, all other child processes are terminated and then all child processes (including the terminated one) are restarted. REST FOR ONE

If a child process terminates, the “rest” of the child processes, i.e., the child processes after the terminated one in start order, are terminated. Then the terminated child process and the rest of the child processes are restarted. SIMPLE ONE FOR ONE

Similar to :one_for_one but suits better when dynamically attaching children. This strategy requires the supervisor specification to contain only one child. Many functions in this module behave slightly differently when this strategy is used.

2. Determine the restart threshold: This reads: Using a one for all strategy, allow for a maximum of 3 restarts within 5 seconds.

SUBSCRIBE TO GET MORE CHEAT SHEETS + UPDATES (Psst! Get a discount coupon to The Little Elixir and OTP Guidebook! When you sign up)

Move seamlessly from learning the basics of Elixir to mastering the key concepts of OTP. – Roberto Infante, Devqf Ltd. Offers techniques and insights difficult or impossible to find anywhere else. – Kosmas Chatzimichalis, Mach7x

I WANT TO BE NOTIFIED!

Copyright © Benjamin Tan Wei Hao. Free to use without modification for non-commercial applications.

Supervisor - GitHub

When given an integer, the supervisor terminates the child process using. Process.exit(child, :shutdown) and waits for an exist signal within the time.

526KB Sizes 36 Downloads 289 Views

Recommend Documents

Anonymous Go-Kart: Specification Report Supervisor - GitHub
May 9, 2011 - [email protected] (83238549). Wim Looman ... Department of Computer and Electrical Engineering. University of ... kart, so that it can be easily controlled by a laptop. The second is to ..... BostonDynamicsTRQ6Sep09.pdf.

Field Supervisor Zanzibar.pdf
Review data compiled every day for quality assurance. Re-interview 1-2 households each day for quality control assessment. Inform the Project Coordinator ...

osssc supervisor notification.pdf
Secondary Education Odisha or equivalent certificate issued by recognized. Board/ Council/ Indian University shall only be accepted. B. Other Eligibility Criteria: ...

Field Supervisor Zanzibar.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Field Supervisor Zanzibar.pdf. Field Supervisor Zanzibar.pdf. Open. Extract. Open with. Sign In. Main menu.M

Application-WAPCOS-Limited-Supervisor-Project-Manager-Other ...
Retrying... Whoops! There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Application-WAPCOS-Limited-Supervisor-Project-Manager-Other-Posts.pdf. Application-WAPCO

WORK SUPERVISOR - OVERSEER GRADE II - DRAUGHTSMAN ...
A 6 4rl2ol1,. IP,T.O.I. Page 3 of 12. Main menu. Displaying WORK SUPERVISOR - OVERSEER GRADE II - DRAUGHTSMAN GRADE II.pdf. Page 1 of 12.

Non MFT Supervisor Information Form.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Non MFT ...

PGCIL Field Engineer-Supervisor Recritment [email protected] ...
Jharkhand and Under JCP Consultancy construction of sub-stations and transmission lines at various places. across Jharkahand , for which we are planning to engage manpower on short term contract basis. The. engagement shall be purely on temporary & c

Qualified Clinical Supervisor Training -
$5 daily parking pass. Location: University of ... Materials prepared and presented by Region 2 FCA, P.O. Box 300457, Fern Park, Florida 32730-0457. For more ...

On Distributed and Parameterized Supervisor Synthesis Problems
conference version has appeared in [7]. ... v0,w = vn and for each i ∈ [1,n], there exist ui,ui and ai,bi such that (ai,bi) ∈ I,vi−1 = uiaibiui and vi = uibiaiui. The.

Senior Administration Officer Supervisor -
Mar 29, 2017 - Supervisor. : Administration Manager ... Support the management of the Administration function of the office ... Ensure proper storage of goods.

Directorate of Employment and Training Supervisor Instructor ...
Mar 20, 2016 - A. Key_A. B. Key_B. C. Key_C. D. Key_D. 1. D. 1. A. 1. C. 1. A. 2. B. 2. C. 2. D. 2. C. 3. A. 3. D. 3. A. 3. B. 4. C. 4. D. 4. B. 4. D. 5. D. 5. B. 5. A. 5. B.

Notification-IRCON-Work-Engineer-Site-Supervisor-Posts.pdf ...
The Company has recorded a turnover of more than ... Application is liable to be rejected if it is not system generated or is unsigned or ... Necessary documents.

Hygiene Promotion Officer Supervisor -
To supervise and manage all CRS Hygiene Promotion interventions in ... of Community Hygiene Promotors, their performance management and provide.

Community Leisure Centre Supervisor JD & PS.docx.pdf ...
RESPONSIBLE TO: Headteacher/ The Premises and Contracts Manager. STAFF MANAGED: ... The post holder will. do this by promoting good customer relations and assisting in the ... putting away equipment after use properly. Support the ...

SIDCGL-Goa-Supervisor-Helper-Posts-Notification-Application.pdf ...
Page 1 of 2. Sewerage & Infrastructural Development Corporation of Goa Ltd. (A Government of Goa Undertaking). Ishan Building, 2nd floor, Opp. CCP,. Panaji – Goa. Email: [email protected]. No. SIDCGL/ADMN-14/5984 /16-17 Dated: – 24/06/2016. Applica

MEAL Officer -Yumbe Supervisor -
qualitative and quantitative methods, conduct data entry and analysis. ... development of effective data collection tools for routine monitoring, project databases.

NAVIGATIONAL SUPERVISION: SUPERVISOR AS ...
Social constructionism and the philosophy of Taoism formed the ... I have found that my most useful navigational tool when encountering a “block” is to ... carefully listen to the therapist's unfolding story without suggesting solutions. .... bes

On Distributed and Parameterized Supervisor Synthesis Problems
regular language has a non-empty decomposable sublanguage with respect to a fixed ..... Proof: It is clear that the supremal element L. ↑. 1 of {L1 ⊆. Σ∗.

Non MFT Supervisor Information Form.pdf
Sign in. Page. 1. /. 2. Loading… Page 1 of 2. Page 1 of 2. Page 2 of 2. Page 2 of 2. Non MFT Supervisor Information Form.pdf. Non MFT Supervisor Information Form.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying Non MFT Supervisor Infor

Public Doc supervisor demand Amherst.pdf
Download. Connect more apps... Try one of the apps below to open or edit this item. Public Doc supervisor demand Amherst.pdf. Public Doc supervisor demand ...

WORK SUPERVISOR-STATE FARMING CORPORATION LTD ...
WORK SUPERVISOR-STATE FARMING CORPORATION LTD-2017May@PSC WINNERS.pdf. WORK SUPERVISOR-STATE FARMING CORPORATION ...