Skip to content

Commit

Permalink
Add namespace prefix for wolfmq_workers_sup
Browse files Browse the repository at this point in the history
  • Loading branch information
kostiushkin committed Dec 13, 2018
1 parent cfe0c21 commit 66ebeef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/wolfmq.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ push({GroupId, _QId} = QueueId, Msg, Opts) when is_atom(GroupId) ->
end,
add_to_queue(QueueId, Msg);
push(QueueId, Msg, Opts) ->
push({wolfmq_default_group, QueueId}, Msg, Opts).
push({default, QueueId}, Msg, Opts).

size({GroupId, _QId} = QueueId) when is_atom(GroupId) ->
case wolfmq_queues_catalog:is_existing(QueueId) of
Expand All @@ -35,7 +35,7 @@ size({GroupId, _QId} = QueueId) when is_atom(GroupId) ->
0
end;
size(QueueId) ->
size({wolfmq_default_group, QueueId}).
size({default, QueueId}).

%% internal
add_to_queue(ExternalQueueId, Msgs) when is_list(Msgs) ->
Expand Down
12 changes: 10 additions & 2 deletions src/wolfmq_workers_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

%% API
start_link(GroupId) ->
supervisor:start_link({local, GroupId}, ?MODULE, []).
Name = group_id_to_process_name(GroupId),
supervisor:start_link({local, Name}, ?MODULE, []).

start_worker(GroupId, QueueId, Opts) ->
supervisor:start_child(GroupId, [[QueueId, Opts]]).
Name = group_id_to_process_name(GroupId),
supervisor:start_child(Name, [[QueueId, Opts]]).

%% supervisor callbacks
init([]) ->
Expand All @@ -26,3 +28,9 @@ init([]) ->
modules => [wolfmq_worker]
},
{ok, {{simple_one_for_one, 250, 5}, [Worker]}}.

%% internal
group_id_to_process_name(GroupId) ->
Id = atom_to_binary(GroupId, utf8),
Name = <<"wolfmq_group_sup_", Id/binary>>,
binary_to_atom(Name, utf8).

0 comments on commit 66ebeef

Please sign in to comment.