批处理和批量处理的模式
我从数据库中查询到的数据看起来很像下面的
Job Site File List
-------------------------------
1 SiteA file2.txt 2
2 SiteB file2.txt 2
3 SiteA file23.txt 23
4 SiteC file2.txt 2
5 SiteB file12.txt 12
6 SiteA file29.txt 29
7 SiteB file28.txt 28
内容,我应该为每个站点(站点 A、B 和 C)启动实例,然后进行处理,即,对于站点 A,进行处理file2.txt、file23.txt 和文件29.txt。这种“处理”可以按某种顺序发生,但必须一个接一个地进行(不是同时进行)。
所以我的第一个任务是整理站点 - 并为每个站点创建实例。我该怎么做?
PS:我认为对于处理部分,我应该使用某种迭代器模式...我更喜欢任何现代编译器语言的解决方案...如 c#、vb、c++ 等...
I've data queried from the db that looks a lot like the following
Job Site File List
-------------------------------
1 SiteA file2.txt 2
2 SiteB file2.txt 2
3 SiteA file23.txt 23
4 SiteC file2.txt 2
5 SiteB file12.txt 12
6 SiteA file29.txt 29
7 SiteB file28.txt 28
I am supposed to initiate instances for each site (sites A, B & C), and then do processing with, i.e., for eg, for siteA, work on file2.txt, file23.txt & file29.txt. This "processing" can happen in some order, but it has to be one after the other (not simultaneous).
So my 1st task is the collate the sites - and create instances for each. How do I do this?
PS: I figured for the processing part I should use some sort of an iterator pattern...I prefer solutions in any modern complier language...like c#, vb, c++, etc...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定我是否理解您想要实现的目标,但我认为您需要做的是:
Site
的不同值2.1.实例化站点
2.2.获取
File
的所有关联值并处理每个值在使用 LINQ 的 C# 中,它会是这样的:
I'm not sure if I have understood what you want to achieve, but I think that what you need to do is:
Site
from your data2.1. Instantiate the site
2.2. Get all the associated values of
File
and process each oneIn C# using LINQ, it would be something like this:
我将有一个带有哈希表的访问者对象,该哈希表迭代每个条目。
对于每个条目:
- 如果哈希表中不存在,访问者对象将为它实例化一个站点。
- 然后对象将获取文件并处理它。
这样做的优点是您可以一次性完成分组和处理。
I would have a visitor object with a hash table which iterated over each entry.
For each entry:
- if it didn't exist in the hash table, the visitor object would instantiate a site for it.
- the object would then get the file and process it.
This would have the advantage that you would do the grouping and processing in one pass.
我赞同每个站点都有一名工人的想法。
另外一个问题是应用程序状态。
当你的应用程序启动时,它关心之前发生了什么吗?考虑处理一些文件后应用程序崩溃。重新启动后,应用程序可能会再次处理文件吗?这是一个问题吗?
I endorse the idea of a worker for each site.
One additional problem - application state.
When your app starts does it care what happened before? Consider an application crash when a few of the files have been processed. On restart presumably the app will process the files again? Is that a problem?