Open naturallymitchell opened 6 years ago
can we make the IF and the THEN segments separate?
priority: 2
if request.method == "GET"
and #request.path_segments == 2
and request.path_segments[1]:match("%a+") -- TODO: make it a known type, not just any word
and request.path_segments[2]:match(utils.uuid_pattern)
--and string.match( request.headers["accept"], "json" )
then
events["request_document_json"]:trigger(request)
end
priority: 2
event: "request_document_json"
parameter: "request"
request.method == "GET"
and #request.path_segments == 2
and request.path_segments[1]:match("%a+") -- TODO: make it a known type, not just any word
and request.path_segments[2]:match(utils.uuid_pattern)
--and string.match( request.headers["accept"], "json" )
that's the THEN, what about the IF?
we need to separate the IF so that we can put a log.trace after it in the generated version which has rule_name evaluated as true or false
Rules have their parameters, before it gets called we need to call get_action_parameters.
get_action_parameters checks input parameters of each action in each event that the rule could call and it is assigning them to the rule parameters(because the rule have to have them to pass them to the event when triggering)
Rule interpreter should generate log.trace("[rule name] evaluated as TRUE") in THEN segment
read the actions associate with the events to trigger, and populate them in the trigger
Call the rules with every possible parameter to get rid of arguments table in the rules loader
function to read each action's parameters for each event
when generating rules, we take events and get events_actions_parameters
when calling rules launcher, we take every events' events_actions_parameters and use that as the argument for calling rules
Rule before:
weight: 10
parameters: ["request", "events"]
event: ["incoming_request_received"]
some condtional and other conditional
Rule after:
local log = require "log"
local weight = 10
local event = "incoming_request_received"
local function rule(rule_argument, p1, p2, p3, p4, ...)
log.debug('[Rule] [0m[4mrespond_to_any_request.lua[0m with weight 10 starting to evaluate')
if true then
events[event]:trigger(p3, p4)
log.trace("[respond_to_any_reqest] rule evaluated to true")
end
log.debug('[Rule] [0m[4mrespond_to_any_request.lua[0m evaluated succesfully')
end
return{
rule = rule,
weight = weight,
}
Action before:
event: ["incoming_request_received"]
weight: 1
input_parameters: ["p1", "p2"]
response = {
headers = {
["content-type"] = "text/plain",
},
body = "hello" .. p1
}
return response
Action after:
local event = { "incoming_request_received" }
local weight = 1
local log = require "log"
local input_parameters = { "p1" , "p2" }
local function action(p1, p2)
response = {
headers = {
["content-type"] = "text/plain",
},
body = "hello" .. p1
}
return response
end
return{
event = event,
action = action,
weight = weight,
input_parameters = input_parameters
}
We should make every possible action parameters table, in package_loader after we interpreted all of the actions and before we patch any of the rules.
The table of parameters for event/events that the specific rule can call will be created in the rule function before we trigger the event/events.
mitchell for each rules' events' actions' parameters make a table(edited) two tables: each and every rule_events_actions_parameters rules_events_actions_parameters
Aleksander Włodarczyk every_events_actions_parameters
last step of if, evaluated as TRUE else, evaluated as FALSE
log.trace("[rule name] evaluated as TRUE")
and separate 'event' to trigger and 'parameter' with it