Skip to content

Commit

Permalink
fix stop/start
Browse files Browse the repository at this point in the history
  • Loading branch information
pankajsoni19 committed Jun 10, 2020
1 parent ea87c67 commit 4796095
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 SoftwareJoint - Erlang, XMPP, Ejabberd & Servers
Copyright (c) 2016-2020 SoftwareJoint - Erlang, XMPP, Ejabberd & Servers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 5 additions & 1 deletion src/fcm.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-module(fcm).

-author('pankajsoni19@live.com').

-behaviour(gen_server).

-include("logger.hrl").
Expand All @@ -25,7 +27,7 @@ start_pool_with_json_service_file(Name, FilePath) ->

-spec stop(atom()) -> ok.
stop(Name) ->
gen_server:stop(Name, normal, 5000).
gen_server:call(Name, stop).

-spec push(
atom(),
Expand Down Expand Up @@ -68,6 +70,8 @@ handle_call({send, RegIds, Message, _Retry}, _From, State0) ->
{ok, Reply, State} = fcm_api_v1:push(RegIds, Message, State0),
{reply, Reply, State};

handle_call(stop, _From, State) ->
{stop, normal, stopped, State};
handle_call(_Request, _From, State) ->
{reply, ok, State}.

Expand Down
2 changes: 2 additions & 0 deletions src/fcm_api_v1.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-module(fcm_api_v1).

-author('pankajsoni19@live.com').

-include("logger.hrl").

-export([push/3]).
Expand Down
2 changes: 2 additions & 0 deletions src/fcm_app.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-module(fcm_app).

-author('pankajsoni19@live.com').

-behaviour(application).

-export([start/2, stop/1]).
Expand Down
19 changes: 14 additions & 5 deletions src/fcm_sup.erl
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
-module(fcm_sup).

-author('pankajsoni19@live.com').

-behaviour(supervisor).

-export([start_link/0, start_child/2]).
%% supervisor init
-export([start_link/0]).

%% supervisor callbacks
-export([init/1]).

%% function exports
-export([start_child/2]).

-define(CHILD(I, Type), {I, {I, start_link, []}, transient, 5000, Type, [I]}).

-spec start_link() -> {ok, pid()}.
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).

%% supervisor callbacks
-spec init([]) -> {ok, {{supervisor:strategy(), 5, 10}, [supervisor:child_spec()]}}.
init([]) ->
{ok, {{simple_one_for_one, 5, 10}, [?CHILD(fcm, worker)]}}.

-spec start_child(atom(), map()) ->
{'error',_} | {'ok','undefined' | pid()} | {'ok','undefined' | pid(),_}.
start_child(Name, Opts) ->
supervisor:start_child(?MODULE, [Name, Opts]).

-spec init([]) -> {ok, {{supervisor:strategy(), 5, 10}, [supervisor:child_spec()]}}.
init([]) ->
{ok, {{simple_one_for_one, 5, 10}, [?CHILD(fcm, worker)]}}.

0 comments on commit 4796095

Please sign in to comment.