/home/runner/work/pgec/pgec/_site/ct/ct_run.ct_pgec@fv-az651-965.2023-12-04_14.30.54/pgec_storage_backfill.COVER.html

1 %% Copyright (c) 2023 Peter Morgan <peter.james.morgan@gmail.com>
2 %%
3 %% Licensed under the Apache License, Version 2.0 (the "License");
4 %% you may not use this file except in compliance with the License.
5 %% You may obtain a copy of the License at
6 %%
7 %% http://www.apache.org/licenses/LICENSE-2.0
8 %%
9 %% Unless required by applicable law or agreed to in writing, software
10 %% distributed under the License is distributed on an "AS IS" BASIS,
11 %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 %% See the License for the specific language governing permissions and
13 %% limitations under the License.
14
15
16 -module(pgec_storage_backfill).
17
18
19 -export([callback_mode/0]).
20 -export([handle_event/4]).
21 -import(pgec_statem, [nei/1]).
22 -import(pgec_storage_common, [pt/1]).
23 -include("pgec_storage.hrl").
24 -include_lib("kernel/include/logger.hrl").
25
26
27 callback_mode() ->
28
:-(
handle_event_function.
29
30
31 handle_event({call, _}, _, _, _) ->
32
:-(
{keep_state_and_data, postpone};
33
34 handle_event(internal, {missing, Detail}, _, Data) ->
35
:-(
BK = #{bucket => <<"pgec/mapping">>,
36 key => pt(Detail)},
37
:-(
{next_state,
38 {waiting_for, BK},
39 Data,
40 nei({get, BK})};
41
42 handle_event(internal,
43 {response,
44 #{reply := {ok, Value},
45 label := #{key := Key,
46 bucket := Bucket}}} = EventContent,
47 {waiting_for,
48 #{key := Key,
49 bucket := Bucket}} = State,
50 #{previous := {ready, _} = Previous,
51 mappings := Mappings} = Data) ->
52
:-(
?LOG_DEBUG(#{event_content => EventContent,
53 state => State,
54
:-(
data => Data}),
55
:-(
ets:insert(Mappings, {Key, Value}),
56
:-(
{next_state,
57 Previous,
58 maps:without([previous], Data),
59 pop_callback_module};
60
61 handle_event(internal,
62 {response, #{reply := not_found}},
63 {waiting_for, _},
64 _) ->
65
:-(
{stop, not_found};
66
67 handle_event(EventType, EventContent, State, Data) ->
68
:-(
pgec_storage_common:handle_event(EventType,
69 EventContent,
70 State,
71 Data).
Line Hits Source