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
-
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_time
must 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
nil
values 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 startdatetime
value.owner()
: returns the associated user (username) to the task.closure()
: returns the closure attached to the Task.err()
: returns the error value attached.nil
if 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_at
value 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:nil
and 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_at
unchanged, success, one time task, create aTASK_DELETE
change.> run_at
, create aTASK_AGAIN
change.* null
, task is already cleared andTASK_DELETE
change has been created.* null
, task is already cleared andTASK_DELETE
change has been created.=run_at
unchanged, create aTASK_ERROR
change.>run_at
, create both aTASK_AGAIN
andTASK_ERROR
change. In that order to AGAIN can set success, and ERROR overwrites.* null
, task is already cleared andTASK_DELETE
change has been created.* null
, task is already cleared andTASK_DELETE
change 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_at
to 0. must be checked at the last time possible. (when processing the event).Parsing a
task
into thestr
function should returntask:123
ortask:nil
if the task is no longer subscribed.Only the functions
task
andtasks
must be scope restricted as the rest follows automatically.Beta Was this translation helpful? Give feedback.
All reactions