fix issue
This commit is contained in:
parent
70d624aeb4
commit
7bdaad2013
@ -8,11 +8,12 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(iot_issue).
|
-module(iot_issue).
|
||||||
-author("licheng5").
|
-author("licheng5").
|
||||||
|
-include("iot.hrl").
|
||||||
|
|
||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/0]).
|
-export([start_link/1]).
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
|
||||||
@ -20,18 +21,22 @@
|
|||||||
-define(SERVER, ?MODULE).
|
-define(SERVER, ?MODULE).
|
||||||
|
|
||||||
-record(state, {
|
-record(state, {
|
||||||
|
issue :: #issue{}
|
||||||
}).
|
}).
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
get_name(IssueId) when is_integer(IssueId) ->
|
||||||
|
list_to_atom("iot_issue:" ++ integer_to_list(IssueId)).
|
||||||
|
|
||||||
|
|
||||||
%% @doc Spawns the server and registers the local name (unique)
|
%% @doc Spawns the server and registers the local name (unique)
|
||||||
-spec(start_link() ->
|
-spec(start_link(Issue :: #issue{}) ->
|
||||||
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
|
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
|
||||||
start_link() ->
|
start_link(Issue = #issue{issue_id = IssueId}) ->
|
||||||
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
|
Name = get_name(IssueId),
|
||||||
|
gen_server:start_link({local, Name}, ?MODULE, [Issue], []).
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% gen_server callbacks
|
%%% gen_server callbacks
|
||||||
@ -42,8 +47,9 @@ start_link() ->
|
|||||||
-spec(init(Args :: term()) ->
|
-spec(init(Args :: term()) ->
|
||||||
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
||||||
{stop, Reason :: term()} | ignore).
|
{stop, Reason :: term()} | ignore).
|
||||||
init([]) ->
|
init([Issue]) ->
|
||||||
{ok, #state{}}.
|
lager:debug("iot_issue started!!"),
|
||||||
|
{ok, #state{issue = Issue}}.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
%% @doc Handling call messages
|
%% @doc Handling call messages
|
||||||
|
|||||||
@ -8,11 +8,12 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(iot_issue_sup).
|
-module(iot_issue_sup).
|
||||||
-author("licheng5").
|
-author("licheng5").
|
||||||
|
-include("iot.hrl").
|
||||||
|
|
||||||
-behaviour(supervisor).
|
-behaviour(supervisor).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/0]).
|
-export([start_link/0, start_issue/1]).
|
||||||
|
|
||||||
%% Supervisor callbacks
|
%% Supervisor callbacks
|
||||||
-export([init/1]).
|
-export([init/1]).
|
||||||
@ -58,3 +59,15 @@ init([]) ->
|
|||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
|
%% 启动一个任务
|
||||||
|
-spec start_issue(Issue :: #issue{}) -> {ok, Pid :: pid()} | {error, Reason :: any()}.
|
||||||
|
start_issue(Issue = #issue{}) ->
|
||||||
|
case supervisor:start_child(?MODULE, [Issue]) of
|
||||||
|
{ok, Pid} ->
|
||||||
|
{ok, Pid};
|
||||||
|
{error, {'already_started', Pid}} ->
|
||||||
|
{ok, Pid};
|
||||||
|
Error ->
|
||||||
|
Error
|
||||||
|
end.
|
||||||
@ -14,6 +14,20 @@
|
|||||||
-export([insert_hosts/0, insert_services/1, insert_terminals/1, insert_routers/0]).
|
-export([insert_hosts/0, insert_services/1, insert_terminals/1, insert_routers/0]).
|
||||||
-export([start_router/1]).
|
-export([start_router/1]).
|
||||||
-export([rsa_encode/1]).
|
-export([rsa_encode/1]).
|
||||||
|
-export([start_issue/0]).
|
||||||
|
|
||||||
|
start_issue() ->
|
||||||
|
iot_issue_sup:start_issue(#issue{
|
||||||
|
issue_id = 1,
|
||||||
|
name = <<"issue 1">>,
|
||||||
|
uid = 1234,
|
||||||
|
deploy_type = 1,
|
||||||
|
assoc_id = 1,
|
||||||
|
hosts = [<<"host1">>, <<"host2">>],
|
||||||
|
timeout = 6,
|
||||||
|
create_ts = 0,
|
||||||
|
status = 0
|
||||||
|
}).
|
||||||
|
|
||||||
insert_hosts() ->
|
insert_hosts() ->
|
||||||
lists:foreach(fun(Id0) ->
|
lists:foreach(fun(Id0) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user