What are patterns/types of task queues? Can the multi-level task queue exist in form of a N-tree?

穿精又带淫゛_ 提交于 2019-12-11 06:42:59

问题


I still didn't discovered a widely accepted pattern for following situation:

In the database, a three-level deep series of tasks exists.

  1. Main task: gather data for user X; report data;
  2. Sub-task: ensure that all data is fetched and is correct; report success or errors
  3. Minimal task: get a piece of data from network, match it against some template (described by both levels above); report I/O errors or template matching errors.

Currently I am only sure to have a comparator object that checks minimal task's state, and a two state transaction machines, first to check minimal task's and second to implement a state advance over all three levels.

But don't want to write a braindead code that will suffer just because of task state access methods spread between sub-objects/methods, so parent-state->child-state->action-state relations are seem to be bad idea, resulting in a code like if ($level1object->subtasks->subtasks->subtasks_completed) { ... }.

Patternized code should either just look clean and have just getNextMiniTask .. getErrorStateForMainTask methods, or use some other architecture to watch over tasks.

Looking for a good sample of such a job queue, since don't want to invent a square wheel bike. abstract, Java, SQL stored procedures/Hibernate, PHP welcome.

P.S. Suggesting it may result in a some form of n-dimensional tree, where possible decisions are making sub-levels or making the whole branch to stop and throw error. However, still looking for sample code.


回答1:


May be thread pool pattern will help



来源:https://stackoverflow.com/questions/3929679/what-are-patterns-types-of-task-queues-can-the-multi-level-task-queue-exist-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!