./ct_report/coverage/mod_pubsub_cache_backend.COVER.html

1 -module(mod_pubsub_cache_backend).
2
3 -export([start/2,
4 stop/1,
5 upsert_last_item/5,
6 delete_last_item/2,
7 get_last_item/2]).
8
9 -ignore_xref([stop/1]).
10
11 -define(MAIN_MODULE, mod_pubsub_cache).
12
13 %%====================================================================
14 %% Behaviour callbacks
15 %%====================================================================
16
17 %% ------------------------ Backend start/stop ------------------------
18
19 -callback start(jid:lserver()) -> ok.
20
21 -callback stop() -> ok.
22
23 -callback upsert_last_item(ServerHost :: binary(),
24 Nidx :: mod_pubsub:nodeIdx(),
25 ItemID :: mod_pubsub:itemId(),
26 Publisher :: jid:jid(),
27 Payload :: mod_pubsub:payload()) -> ok | {error, Reason :: term()}.
28
29 -callback delete_last_item(ServerHost :: binary(),
30 Nidx :: mod_pubsub:nodeIdx()) -> ok | {error, Reason :: term()}.
31
32 -callback get_last_item(ServerHost :: binary(),
33 Nidx :: mod_pubsub:nodeIdx()) ->
34 {ok, LastItem :: mod_pubsub:pubsubLastItem()} | {error, Reason :: term()}.
35
36 -spec start(jid:lserver(), gen_mod:module_opts()) -> ok.
37 start(ServerHost, Opts = #{last_item_cache := CacheBackend}) ->
38 % mongoose_backend extracts the "backend" option, but the cache backend is under the "last_item_cache" key
39 % the "backend" from Opts relates to the backend for mod_pubsub
40 3 OptsWithBackend = Opts#{backend => CacheBackend},
41 3 TrackedFuns = [upsert_last_item, delete_last_item, get_last_item],
42 3 mongoose_backend:init(ServerHost, ?MAIN_MODULE, TrackedFuns, OptsWithBackend),
43 3 Args = [ServerHost],
44 3 mongoose_backend:call(ServerHost, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
45
46 -spec stop(jid:lserver()) -> ok.
47 stop(ServerHost) ->
48
:-(
mongoose_backend:call(ServerHost, ?MAIN_MODULE, ?FUNCTION_NAME, []).
49
50 -spec upsert_last_item(ServerHost :: binary(),
51 Nidx :: mod_pubsub:nodeIdx(),
52 ItemID :: mod_pubsub:itemId(),
53 Publisher :: jid:jid(),
54 Payload :: mod_pubsub:payload()) -> ok | {error, Reason :: term()}.
55 upsert_last_item(ServerHost, Nidx, ItemID, Publisher, Payload) ->
56 14 Args = [ServerHost, Nidx, ItemID, Publisher, Payload],
57 14 mongoose_backend:call_tracked(ServerHost, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
58
59 -spec delete_last_item(ServerHost :: binary(),
60 Nidx :: mod_pubsub:nodeIdx()) -> ok | {error, Reason :: term()}.
61 delete_last_item(ServerHost, Nidx) ->
62 2 Args = [ServerHost, Nidx],
63 2 mongoose_backend:call_tracked(ServerHost, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
64
65 -spec get_last_item(ServerHost :: binary(),
66 Nidx :: mod_pubsub:nodeIdx()) ->
67 {ok, LastItem :: mod_pubsub:pubsubLastItem()} | {error, Reason :: term()}.
68 get_last_item(ServerHost, Nidx) ->
69 8 Args = [ServerHost, Nidx],
70 8 mongoose_backend:call_tracked(ServerHost, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
Line Hits Source