批处理和批量处理的模式

发布于 2024-08-12 01:31:45 字数 538 浏览 5 评论 0原文

我从数据库中查询到的数据看起来很像下面的

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不乱于心 2024-08-19 01:31:45

我不确定我是否理解您想要实现的目标,但我认为您需要做的是:

  1. 从您的数据中获取 Site 的不同值
  2. 对于在上一步
    2.1.实例化站点
    2.2.获取 File 的所有关联值并处理每个值

在使用 LINQ 的 C# 中,它会是这样的:

var siteNames=data.Select(d => d.Site).Distinct();
foreach(var siteName in siteNames) {
    var site=new Site(siteName); //Or use a factory method, a sites list, etc
    var files=data.Where(d => d.Site==site).Select(d => d.File);
    foreach(var file in Files) {
        site.ProcessFile(file);
    }
}

I'm not sure if I have understood what you want to achieve, but I think that what you need to do is:

  1. Get the distinct values of Site from your data
  2. For each of the values obtained in the previous step
    2.1. Instantiate the site
    2.2. Get all the associated values of File and process each one

In C# using LINQ, it would be something like this:

var siteNames=data.Select(d => d.Site).Distinct();
foreach(var siteName in siteNames) {
    var site=new Site(siteName); //Or use a factory method, a sites list, etc
    var files=data.Where(d => d.Site==site).Select(d => d.File);
    foreach(var file in Files) {
        site.ProcessFile(file);
    }
}
月下伊人醉 2024-08-19 01:31:45

我将有一个带有哈希表的访问者对象,该哈希表迭代每个条目。

对于每个条目:
- 如果哈希表中不存在,访问者对象将为它实例化一个站点。
- 然后对象将获取文件并处理它。

这样做的优点是您可以一次性完成分组和处理。

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.

折戟 2024-08-19 01:31:45

我赞同每个站点都有一名工人的想法。

另外一个问题是应用程序状态。

当你的应用程序启动时,它关心之前发生了什么吗?考虑处理一些文件后应用程序崩溃。重新启动后,应用程序可能会再次处理文件吗?这是一个问题吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文