Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. create "TaskQueue" class
  2. add protected "TaskQueue::createTaskHandler($class_name)" method, that will:
    1. create instance of given class or throw an exception when failed
    2. if created object doesn't implement "ITaskHandler" interface, then throw an exception
    3. return the object
  3. add public "TaskQueue::addTask($task_handler_class, $task_data, $scheduled_on, $max_retries = null)" method, that will:
    1. call "TaskQueue::createTaskHandler" method to verify, that class given in "$task_handler_class" parameter is valid
    2. consider "$max_retries" as "5" when not given
  4. add public "TaskQueue::refreshTaskRunnersStatus()" method that will:
    1. get all "task-runner" in "running" status
    2. if associated process isn't running anymore, then set "task-runner" status from "running" to "timeout" (the "task-runner::OnAfterItemUpdate" would update connected task runs)
  5. add protected "TaskQueue::createTaskRun(kDBItem $task_queue)" method, that:
    1. will create new task run (and return it's ID) for given queue record, when all of following rules aren't violated:
      1. only 1 (or less) running "task-run" can exist for one "task-queue" record
      2. "TaskRunsFailed" must be smaller, then "MaxRetries" on associated "task-queue" record
    2. return "null" otherwise
  6. add protected "TaskQueue::createMissingTaskRuns()" method, that will:
    1. get all records from "TaskQueue" table, for which task runs can be created:
      1. ScheduledOn < NOW()
      2. Status is not "running"
      3. TaskRunsFailed must be smaller, then MaxRetries
    2. call the "TaskQueue::createTaskRun" method on each of them (method can return "NULL" in some cases, but that's ok)
  7. add protected "TaskQueue::getTaskRunnerCount()" method, that will return number of "task-runner" in "running" status
  8. add protected "TaskQueue::getMissingTaskRunnerCount()" method, that will:
    1. get value of  "TaskRunnerLimit" system setting
    2. call "TaskQueue::getTaskRunnerCount" method
    3. return difference or 0, when difference is negative
  9. add protected "TaskQueue::createMissingTaskRunners()" method, that will:
    1. if not in CLI then just do nothing:
      1. call "TaskQueue::getMissingTaskRunnerCount" method
      2. if it returned "0" do nothing
      3. execute command (see last plan) X number of times in background processes (X - number returned above)
    2. if not in CLI:
      1. call "TaskQueue::getTaskRunner" method
      2. if object is returned call "->process()" method on it
  10. add public "TaskQueue::processQueue()" method, that will:
    1. call "TaskQueue::refreshTaskRunnersStatus" method
    2. call "TaskQueue::createMissingTaskRunners" method
    3. call "TaskQueue::createMissingTaskRuns" method
  11. create "task-queue:OnProcess" event, that:
    1. would be called as Scheduled Task on a regular basis (e.g. each 5 minutes)
    2. would call "TaskQueue::processQueue" method

...