如何从数据库队列中出列条目? [英] How dequeue entries from database queue?

查看:251
本文介绍了如何从数据库队列中出列条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用数据库实现了队列。我们的队列表如下所示

UniqueID(代表我们的内部ID)

状态

LastUpdateed



我们的Timer任务持续监视上面的表并每次获取一条记录并将状态更改为正在进行并分配给执行该任务的线程。

此处计时器保持在-bogress条目全局。



线程归档,记录完成任务并从正在进行的条目中删除该条目。

这里我们应该限制为同一个UniqueID一次获取多个更新。由于这个原因,当计时器通过使用不在下面的选择查询中获取正在进行的条目以外的记录时



从FastLaneQueue中选择*,其中status = 0且UniqueID not在(1,2,3)限制1



我们将如何实现上述场景而不使用in因为不好用。



如果你有任何其他方法可以实施上述情况请建议



我有什么试过:



计时器通过在下面的select select中使用not来取得正在进行的条目以外的记录select * from FastLaneQueue where status = 0和UniqueID不在(1,2,3)限制1

We have Implemented Queue using database. Our Queue table looks as below
UniqueID(It represent our internal id)
Status
LastUpdateed

Our Timer task continuously monitor the above table and fetching one record every time and changing the status as in-progress and assign to a thread for doing that task.
Here timer maintains in-progress entries globally.

Thread archive that record when it complete the task and remove that entry from in-progress entry.
Here we should restrict to fetch more than one update at a time for same UniqueID. Due to that reason when timer fetch the record other than in-progress entries by using not in select query like below

select * from FastLaneQueue where status=0 and UniqueID not in(1,2,3) limit 1

How we will implement above scenario with out using not in because not in is not good to use.

Please suggest if you have any other ways to implement above case

What I have tried:

Timer fetch the record other than in-progress entries by using not in select query like below select * from FastLaneQueue where status=0 and UniqueID not in(1,2,3) limit 1

推荐答案

我建​​议您在选择项目时将其标记为正在进行中。这样你就不会选择已经读过的任何项目。



我自己这样做的方法是轮询数据库队列中的任何消息尚未找到,将其状态设置为已启动(与正在进行中相同),然后将它们添加到.Net中的队列对象中。 Queue对象更容易处理。





当我的程序启动时,它会重置任何已启动但不会完成如果/当程序崩溃时错过了
I suggest you mark the item as in-progress as soon as it is selected. That way you won't pick up any items already read in.

The way I have done this myself is to "poll" the database queue for any messages that have not yet been found, Set their status to "started" (same as your 'in-progress') then add them to a Queue Object in .Net. The Queue object is much easier to handle.


When My program starts up, it resets any "started" but not "complete" messages back to "new" in case they were missed out if/when the program crashes


这篇关于如何从数据库队列中出列条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆