Hyperlambda tasks

The tasks component allows you to create and administrate persisted Hyperlambda tasks, and/or schedule tasks for executing, either in a repeating pattern somehow, or at an exact date and time in the future. A Magic task again, is really nothing but a snippet of Hyperlambda code, that is persisted into your Magic database, and such can be recalled at any point in the future to be executed at will.

Hyperlambda task scheduler

The idea behind the task component

The idea behind the task scheduler is first of all to allow for creating dynamically persisted tasks that can be triggered by some future event, facilitating for “Business Process Workflows” - In addition to scheduling your tasks to be executed at some specific date and time in the future, and/or in a repeating fashion. Since tasks are dynamically created Hyperlambda snippets of code, this allows you to dynamically create and orchestrate “business process workflows” using the task scheduler, in addition to that you have no restrictions in regards to what you want your scheduled tasks to do, contrary to most other task schedulers, that are often built upon statically compiled programming languages.

Tasks internals

Your tasks will be saved into your Magic database and its table called “tasks”, in addition to your “task_due” table for schedules. This implies that even if your server for some reasons “drops”, and/or is rebooted, your tasks will automatically be re-scheduled as your server restarts. Notice, for tasks repeating every nth unit, this process is not 100% perfect, since it might imply the execution date for your tasks are being moved forward if your server reboots for some reasons.

Scheduling tasks

Tasks can be scheduled according to a whole range of different patterns. First of all you can schedule a task to be executed at some specific date and time in the future. This is done by simply choosing a date and time in the future when you want your task to execute.

Hyperlambda task scheduler

In addition to scheduling a task to be executed at a specific date and time in the future, you can also schedule your task to be repeated according to some sort of repetition pattern. The simplest pattern here is “every n unit”, where n can be any integer, and unit can be any of seconds, minutes, hours, days, weeks and months.

Slightly more complex repetition units can be provided by choosing a custom repetition pattern. There exists two such custom repetition patterns in Magic out of the box, and they are as follows.

Notice, MM, dd, and ww can have double asterix (**) as their values, implying “whatever value”. MM, dd and ww can also have multiple values, separated by the pipe character (|), to provide multiple values for these types. To for instance create a task that is execute on the 5th and 15th of January and February you could use a task such as follows; “01|02.5|”. This is because both the day and the month parts of a monthly repetition value can be piped together declaring multiple months and days, where the task will be executed at any of the days and months you declare in your repetition value. The same is true for the weekdays depetition pattern. If you want to create a scheduled task that repeats every Monday and Friday, you can use a pattern such as follows; “Monday|Friday.23.59.59”. This task will execute one second to midnight both Mondays and Fridays.

To understand which repetition pattern is which, simply count the number of periods in your value, and if there are 4 periods, it’s a month/day type of pattern. If there are only 3 periods in your pattern, it’s a weekday pattern.