fix issue
This commit is contained in:
parent
7bdaad2013
commit
7877753602
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/1]).
|
-export([start_link/1]).
|
||||||
|
-export([get_pid/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]).
|
||||||
@ -21,16 +22,20 @@
|
|||||||
-define(SERVER, ?MODULE).
|
-define(SERVER, ?MODULE).
|
||||||
|
|
||||||
-record(state, {
|
-record(state, {
|
||||||
issue :: #issue{}
|
issue :: #issue{},
|
||||||
|
timer_ref
|
||||||
}).
|
}).
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
|
get_pid(IssueId) when is_integer(IssueId) ->
|
||||||
|
whereis(get_name(IssueId)).
|
||||||
|
|
||||||
get_name(IssueId) when is_integer(IssueId) ->
|
get_name(IssueId) when is_integer(IssueId) ->
|
||||||
list_to_atom("iot_issue:" ++ integer_to_list(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(Issue :: #issue{}) ->
|
-spec(start_link(Issue :: #issue{}) ->
|
||||||
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
|
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
|
||||||
@ -47,9 +52,18 @@ start_link(Issue = #issue{issue_id = IssueId}) ->
|
|||||||
-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([Issue]) ->
|
init([Issue = #issue{timeout = Timeout0, hosts = Hosts}]) ->
|
||||||
lager:debug("iot_issue started!!"),
|
lager:debug("iot_issue started!!: ~p", [Issue]),
|
||||||
{ok, #state{issue = Issue}}.
|
%% 启动任务定时器, 默认最长为1个小时
|
||||||
|
Timeout = if Timeout0 > 0 -> Timeout0; true -> 3600 end,
|
||||||
|
TimerRef = erlang:start_timer(Timeout * 1000, self(), issue_task_timeout),
|
||||||
|
|
||||||
|
%% TODO 下发数据到主机
|
||||||
|
lists:map(fun(Host) ->
|
||||||
|
iot_emqtt_client:publish(Host, x, 1)
|
||||||
|
end, Hosts),
|
||||||
|
|
||||||
|
{ok, #state{issue = Issue, timer_ref = TimerRef}}.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
%% @doc Handling call messages
|
%% @doc Handling call messages
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user