Java / .NET 任务处理库

发布于 2024-08-02 03:56:28 字数 607 浏览 6 评论 0原文

我正在寻找一些好的库来处理 Java 或 .NET 的任务(或我们在域模型中所说的“操作”)。 我们保存要在数据库中执行的每个操作,然后需要某种机制从数据库中获取未处理的任务,处理它们并使用正确的状态更新数据库记录(“已处理正常”/“处理错误”)。

诀窍在于操作可以相互依赖。 例如,当处理“付款操作”时,系统可能会发现我们之前需要执行“检查付款数据操作” - 因此它应该在数据库中创建新的操作行,暂停执行“付款操作”,处理“检查付款数据操作” ' 下一轮完成后返回处理'操作付款'。

我将向您展示我们目前如何处理这个问题。

我们有数据库表“操作”。 类似 Cron 的机制每分钟运行一次,从数据库中获取前 100 个未处理的操作并进行处理。 如果(在处理时)系统发现需要某些其他操作(B)来执行当前操作(A),则创建新的操作(B)记录并停止执行当前操作(A)。 下一分钟 cron 获取操作 A 和 B。操作 A 被获取,因为它尚未处理,但系统发现依赖操作 B 已创建,因此不会再次创建它。 操作 B 已处理,状态“已处理正常”保存在数据库中的正确行中。 下一分钟 cron 从数据库中获取操作 A,并且最终可以执行它,因为相关任务已完成。

我们正在寻找让它变得更简单、更好、更优雅的方法。

I'm looking for some good library for processing tasks (or 'operations' as we call them in our domain model) for Java or .NET. We save each operation to perform in db and then we need some mechanism for fetching unprocessed tasks from db, process them and update db record with proper status ('processed OK' / 'process error').

The trick is that operation can depend one on another. For example when 'Operation Payment' is being processed the system might discover that we need to perform 'Operation Check Payment Data' before - so it should create new operation row in db, pause performing 'Operation Payment', process 'Operation Check Payment Data' in next turn and after it completes go back to processing 'Operation Payment'.

I'll show you how we manage this at the moment.

We've got db table 'operations'. Cron-like mechanism runs each minute and fetches first 100 unprocessed operations from db and process it. If (while processing) system finds that some other operation (B) is needed to perform current operation (A), then new operation (B) record is created and performing current operation (A) is halted. Next minute cron fetches operations A and B. Operation A is fetches as it is not processed but system sees that dependent operation B is already created so it does not create it once again. Operation B is processed and status 'processed OK' is saved in proper row in db. Next minute cron fetches operation A from db and can finally perform it because dependent task is completed.

We are looking for ways to make it simpler, better and more elegant.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

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