dqe_collect_events.erl 890 Bytes
Newer Older
1 2 3 4
-module(dqe_collect_events).

-behaviour(dflow).

Heinz N. Gies's avatar
Heinz N. Gies committed
5
-export([init/2, describe/1, start/2, emit/3, done/2]).
6 7 8

-record(state, {
          acc  = [] :: [maps:map()],
Heinz N. Gies's avatar
Heinz N. Gies committed
9
          mdata :: [{binary(), binary()}],
10 11 12
          name :: binary()
         }).

Heinz N. Gies's avatar
Heinz N. Gies committed
13 14
init([Name, MData], _SubQs) ->
    {ok, #state{mdata = MData, name = Name}}.
15 16 17 18 19 20 21 22 23 24 25 26 27 28

describe(_) ->
    "collect_events".

start(_, State) ->
    {ok, State}.

%% When we get the first data we can calculate both the applied
%% time and the upwards resolution.

emit(_C, Data, State = #state{acc = Acc})
  when is_list(Data) ->
    {ok, State#state{acc = [Data | Acc]}}.

Heinz N. Gies's avatar
Heinz N. Gies committed
29
done(_Child, State = #state{name = Name, acc = Acc, mdata = MData}) ->
30 31
    {done, #{name => Name,
             data => lists:flatten(Acc),
Heinz N. Gies's avatar
Heinz N. Gies committed
32
             metadata => maps:from_list(MData),
33 34 35
             resolution => 1.0e-6,
             type => events},
     State#state{acc = []}}.