Picolab / pico-engine

An implementation of the pico-engine hosted on node.js
http://picolabs.io/
MIT License
43 stars 8 forks source link

schedule event adds to the list but doesn't raise the event when time has elapsed #508

Closed b1conrad closed 3 years ago

b1conrad commented 3 years ago

See slack #pico-engine channel for one experience report

b1conrad commented 3 years ago

Also, used this ruleset to schedule a couple of events

ruleset io.picolabs.schedule {
    meta {
        shares getLog, listScheduled
    }
    global {
        getLog = function(){
            ent:log;
        }
        listScheduled = function(){
            schedule:list();
        }
    }
    rule clear_log {
        select when schedule clear_log

        send_directive("clear_log");

        fired {
            ent:log := []
        }
    }
    rule push_log {
        select when schedule push_log

        send_directive("push_log");

        fired {
            ent:log := ent:log.append(event:attrs)
        }
    }
    rule in_5min {
        select when schedule in_5min

        send_directive("in_5min");

        fired {
            schedule schedule event "push_log"
                at time:add(time:now(), {"minutes": 5})
                attributes {
                    "from": "in_5min",
                    "name": event:attr("name")
                }
                setting(foo);
            ent:log := ent:log.append({"scheduled in_5min": foo})
        }
    }
    rule every_1min {
        select when schedule every_1min

        send_directive("every_1min");

        fired {
            schedule schedule event "push_log"
                repeat "* */1 * * * *"
                attributes {
                    "from": "every_1min",
                    "name": event:attr("name")
                }
                setting(foo);
            ent:log := ent:log.append({"scheduled every_1min": foo})
        }
    }
    rule rm_from_schedule {
        select when schedule rm_from_schedule

        schedule:remove(event:attr("id"));
    }
}
b1conrad commented 3 years ago

And these logs to show nothing happening

Logging
2020-12-26T13:48:02.043Z - QUERY ckj5q44eq00017a2rcvxs8evv io.picolabs.pico-engine-ui/logs {}
2020-12-26T13:47:48.675Z - QUERY ckj5q76io000k7h2rck3g0gi2 io.picolabs.schedule/getLog {}
2020-12-26T13:38:46.286Z - QUERY ckj5q76io000k7h2rck3g0gi2 io.picolabs.schedule/listScheduled {}
2020-12-26T13:38:44.003Z - EVENT ckj5q76io000k7h2rck3g0gi2 schedule:in_5min {"name":"Bob"}
2020-12-26T13:35:36.861Z - QUERY ckj5q76io000k7h2rck3g0gi2 io.picolabs.schedule/listScheduled {}
2020-12-26T13:35:34.589Z - QUERY ckj5q76io000k7h2rck3g0gi2 io.picolabs.schedule/getLog {}
2020-12-26T13:16:04.072Z - QUERY ckj5q76io000k7h2rck3g0gi2 io.picolabs.schedule/listScheduled {}
2020-12-26T13:15:53.765Z - QUERY ckj5q76io000k7h2rck3g0gi2 io.picolabs.schedule/getLog {}
2020-12-26T13:15:38.952Z - EVENT ckj5q76io000k7h2rck3g0gi2 schedule:in_5min {"name":"Alice"}
2020-12-26T13:15:20.037Z - QUERY ckj5q76io000k7h2rck3g0gi2 io.picolabs.schedule/getLog {}
2020-12-26T13:15:18.067Z - EVENT ckj5q76io000k7h2rck3g0gi2 schedule:clear_log {}
b1conrad commented 3 years ago

I have tried sending in a number in case that was the problem, but the event still wasn't scheduled. This is what I tried:

    rule in_5min {
        select when schedule in_5min

        send_directive("in_5min");

        fired {
            schedule schedule event "push_log"
                at time:strftime(time:add(time:now(), {"minutes": 5}),"%s").as("Number")
                attributes {
                    "from": "in_5min",
                    "name": event:attr("name")
                }
                setting(foo);
            ent:log := ent:log.append({"scheduled in_5min": foo})
        }
    }