Replies: 1 comment
-
|
Implemented in v1.1.0 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The current timer implementation is not very intuitive and hard to use for flexible scheduling.
Instead of timers, we could create a "task" type. Like the timer, a task should accept (require) a start time and a closure (required). A repeat value option should be dropped and replaced with more flexible re-scheduling. (more later).
The closure should get itself (the task) as first argument, (this is way better than the id with the previous timers), followed by the given arguments by the argument list.
Creating a task could be done as follow:
A Task
start_timemust be at least "now" or into the future. (thus never can be0).The arguments list should not accept more arguments than accepted by the closure. Less arguments is no problem as they can be filled with
nilvalues like we do in ThingsDB.A task type should accept the following functions:
Functions which do not require a change:
id(): returns the Task Id.at(): returns the Task startdatetimevalue.owner(): returns the associated user (username) to the task.closure(): returns the closure attached to the Task.err(): returns the error value attached.nilif the task has never ran before, the error issuccess (0)when the last run was successful.args(): returns a list with arguments attached to the Task.Functions with a change:
set_args([...]): replace the Task arguments.set_owner([...]): replace the Task owner.cancel(): cancel the Task. The task remains registered except therun_atvalue will be set to zero0.del(): cancels the task if not cancelled already and delete (unsubscribe) the task. All properties of a task will be set tonull. Thus, if a value is attached somewhere as a value, it will be presented astask:niland no other functions will work on this task.Functions must be used within the task's closure: (changes will not be created by these functions but instead after the task has finished) There is no need to mask these as change functions as the task always is guaranteed to have a change anyway.
again_at: schedule a new time for the task (at least one minute after current run).again_in: shortcut foragain_at(task.at().move(....)).Example repeating task:
Calling function task with a task Id return the task with that Id. Only for as long as the task is subscribed and thus is not empty.
Function
tasks()returns a list with all the tasks. This way it is also possible to manage tasks in the@thingsdb.When a task is started:
=run_atunchanged, success, one time task, create aTASK_DELETEchange.> run_at, create aTASK_AGAINchange.* null, task is already cleared andTASK_DELETEchange has been created.* null, task is already cleared andTASK_DELETEchange has been created.=run_atunchanged, create aTASK_ERRORchange.>run_at, create both aTASK_AGAINandTASK_ERRORchange. In that order to AGAIN can set success, and ERROR overwrites.* null, task is already cleared andTASK_DELETEchange has been created.* null, task is already cleared andTASK_DELETEchange has been created.Related changes:
TASK_DELETE: unsubscribe and "clear" a task.TASK_ERROR: set a task error (ex_t).TASK_AGAIN: set the task error to 0, success and re-schedule the task.NEW_TASK: create a new task.SET_TASK_ARGS: set new task arguments.SET_TASK_OWNER: set new task owner.TASK_CANCEL: setrun_atto 0. must be checked at the last time possible. (when processing the event).Parsing a
taskinto thestrfunction should returntask:123ortask:nilif the task is no longer subscribed.Only the functions
taskandtasksmust be scope restricted as the rest follows automatically.Beta Was this translation helpful? Give feedback.
All reactions