问题描述
我仍然没有发现以下情况的广泛接受的模式:
I still didn't discovered a widely accepted pattern for following situation:
在数据库中,存在三层深的系列任务.
In the database, a three-level deep series of tasks exists.
- 主要任务:为用户X收集数据;报告数据;
- 子任务:确保所有数据都被获取并且是正确的;报告成功或错误
- 最小任务:从网络中获取一条数据,将其与某个模板进行匹配(由上述两个级别描述);报告 I/O 错误或模板匹配错误.
目前我只确定有一个比较器对象来检查最小任务的状态,和一个两个状态事务机,首先检查最小任务,然后在所有三个级别上实现状态推进.
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.
但是不想写一个会因为任务状态访问方法在子对象/方法之间传播而遭受痛苦的脑残代码,所以父状态->子状态->动作-状态关系似乎是坏主意,导致代码如下if ($level1object->subtasks->subtasks->subtasks_completed) { ... }.
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 likeif ($level1object->subtasks->subtasks->subtasks_completed) { ... }.
模式化的代码要么看起来很干净并且只有 getNextMiniTask .. getErrorStateForMainTask
方法,或者使用一些其他架构来监视任务.
Patternized code should either just look clean and have just getNextMiniTask .. getErrorStateForMainTask
methods, or use some other architecture to watch over tasks.
正在寻找此类工作队列的良好样本,因为不想发明方轮自行车.抽象、Java、SQL 存储过程/Hibernate、PHP 欢迎使用.
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.
附言建议它可能会导致某种形式的 n 维树,其中可能的决策是制作子级别或使整个分支停止并抛出错误.但是,仍在寻找示例代码.
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.
推荐答案
可能是线程池模式 会有所帮助
这篇关于什么是任务队列的模式/类型?多级任务队列能否以N-tree的形式存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!