Goldrush is a small Erlang app that provides fast event stream processing
To use goldrush in your application, you need to define it as a rebar dep or include it in erlang’s path.
Before composing modules, you’ll need to define a query. The query syntax matches any number of `{erlang, terms}’ and is composed as follows:
Select all events where ‘a’ exists and is greater than 0.
glc:gt(a, 0).
Select all events where ‘a’ exists and is greater than or equal to 0.
glc:gte(a, 0).
Select all events where ‘a’ exists and is equal to 0.
glc:eq(a, 0).
Select all events where ‘a’ exists and is not equal to 0.
glc:neq(a, 0).
Select all events where ‘a’ exists and is less than 0.
glc:lt(a, 0).
Select all events where ‘a’ exists and is less than or equal to 0.
glc:lte(a, 0).
Select all events where ‘a’ exists.
glc:wc(a).
Select all events where ‘a’ does not exist.
glc:nf(a).
Select no input events. User as a black hole query.
glc:null(false).
Select all input events. Used as a passthrough query.
glc:null(true).
Select all events where both ‘a’ AND ‘b’ exists and are greater than 0.
glc:all([glc:gt(a, 0), glc:gt(b, 0)]).
Select all events where ‘a’ OR ‘b’ exists and are greater than 0.
glc:any([glc:gt(a, 0), glc:gt(b, 0)]).
Select all events where ‘a’ AND ‘b’ exists where ‘a’ is greater than 1 and ‘b’ is less than 2.
glc:all([glc:gt(a, 1), glc:lt(b, 2)]).
Select all events where ‘a’ OR ‘b’ exists where ‘a’ is greater than 1 and ‘b’ is less than 2.
glc:any([glc:gt(a, 1), glc:lt(b, 2)]).
Select all events where ‘a’ is equal to 1, ‘b’ is equal to 2 and ‘c’ is equal to 3 and collapse any duplicate logic.
glc_lib:reduce( glc:all([ glc:any([glc:eq(a, 1), glc:eq(b, 2)]), glc:any([glc:eq(a, 1), glc:eq(c, 3)])])).
The previous example will produce and is equivalent to:
glc:all([glc:eq(a, 1), glc:eq(b, 2), glc:eq(c, 3)]).
To compose a module you will take your Query defined above and compile it.
glc:compile(Module, Query). glc:compile(Module, Query, State). glc:compile(Module, Query, State, ResetStatistics).
Begin by constructing an event list.
Event = gre:make([{'a', 2}], [list]).
Now pass it to your query module to be handled.
glc:handle(Module, Event).
Write all input events as info reports to the error logger.
glc:with(glc:null(true), fun(E) -> error_logger:info_report(gre:pairs(E)) end).
Write all input events where `error_level’ exists and is less than 5 as info reports to the error logger.
glc:with(glc:lt(error_level, 5), fun(E) -> error_logger:info_report(gre:pairs(E)) end).
Write all input events where `error_level’ exists and is 3 or 5 as info reports to the error logger.
glc:any([ glc:with(glc:lt(error_level, 3), fun(E) -> error_logger:info_report(gre:pairs(E)) end), glc:with(glc:lt(error_level, 5), fun(E) -> error_logger:info_report(gre:pairs(E)) end)]).
To compose a module with state data you will add a third argument (orddict).
glc:compile(Module, Query, [{stored, value}]).
Return the stored value in this query module.
{ok, value} = glc:get(stored).
Return all stored values in this query module.
[...] = Module:get().
To compose a module with state data you will add a third argument (orddict).
glc:compile(Module, Query, [{stored, value}]).
Return the stored value in this query module.
{ok, value} = glc:get(stored).
To execute a job through the query module, inputting an event on success.
Event = gre:make([{'a', 2}], [list]). {ExecutionTime, Result}= glc:run(Module, fun(Event, State) -> %% do not end with {error, _} or throw an exception end, Event).
Return the number of input events for this query module.
glc:input(Module).
Return the number of output events for this query module.
glc:output(Module).
Return the number of filtered events for this query module.
glc:filter(Module).
Return the number of job runs for this query module.
glc:job_run(Module).
Return the number of job errors for this query module.
glc:job_error(Module).
Return the number of job inputs for this query module.
glc:job_input(Module).
Return the amount of time jobs took for this query module.
glc:job_time(Module).
Return the average time jobs took for this query module.
glc:job_time(Module) / glc:job_input(Module) / 1000000.
Return the query combining the conditional logic of multiple modules
glc_lib:reduce(glc:all([Module1:info('query'), Module2:info('query')]).
Return all statistics from this query module.
glc:info(Module).
$ ./rebar compile
or
$ make
0.1.9
0.1.8
0.1.7
0.1.7
0.1.7
0.1.6
0.1.5
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。