Timer
A timer defines a task that should be executed at a given time or repeatedly at a given interval.
Let’s make the “Hello World” of the timer.
Make a tql script of “Hello World”
Open tql editor, copy the code below and save it as helloworld.tql
.
SCRIPT({
ctx := import("context")
ctx.println("Hello World?")
ctx.yield("message", "Hello World?")
})
MARKDOWN()
Execute the script and it will show a simple record that key is “message” and value is “Hello World?”.
Register task
Open machbase-neo shell and register a new timer to run the script in every 5 seconds.
timer add helloworld "@every 5s" helloworld.tql;
Run timer list
to verify your registration.
machbase-neo» timer list;
╭────────────┬────────────┬────────────────┬───────────┬───────╮
│ NAME │ SPEC │ TQL │ AUTOSTART │ STATE │
├────────────┼────────────┼────────────────┼───────────┼───────┤
│ HELLOWORLD │ @every 5s │ helloworld.tql │ false │ STOP │
╰────────────┴────────────┴────────────────┴───────────┴───────╯
Since we did not set --autostart
option, the state of the task is STOP
.
Make it start to run.
timer start helloworld;
machbase-neo» timer list;
╭────────────┬────────────┬────────────────┬───────────┬─────────╮
│ NAME │ SPEC │ TQL │ AUTOSTART │ STATE │
├────────────┼────────────┼────────────────┼───────────┼─────────┤
│ HELLOWORLD │ @every 5s │ helloworld.tql │ false │ RUNNING │
╰────────────┴────────────┴────────────────┴───────────┴─────────╯
See the machbase-neo server process’s stdout… it will print “Hello World” in every 5 seconds.
2023/08/07 11:44:43.001 INFO timer-helloworld helloworld helloworld.tql start
Hello World?
2023/08/07 11:44:43.001 INFO timer-helloworld helloworld helloworld.tql RUNNING elapsed 862.166µs
Stop the task
timer stop helloworld;
Last updated on