Template for processing queued actions

I have a table containing Queued elements for synchronization issues with another system

TableName | PrimaryKey | Action -------------------------------- Products 15 Delete Products 21 Create Categories 9 Update 

TableName : name of the target SQL table

PrimaryKey : PK value of the target element in the corresponding table

Action : action (Example: if create → Click create an item with identification number 21 of the local Products table on the remote system)

I need a way to deal with C # correctly. I am thinking about using Command Pattern. (ASP.Net MVC4 / C #)

Do you have any recommendations on these issues?

+4
source share
1 answer

You can use the advice in this article and the server-side process queue. Then your code might look like

 create table TQueue (TableName nvarchar(128), PrimaryKey int, Action nvarchar(128)) create procedure sp_TQueue_Pop as begin declare @TableName nvarchar(128), @PrimaryKey int, @Action nvarchar(128) declare @temp_pop table (TableName nvarchar(128), PrimaryKey int, Action nvarchar(128)) begin transaction select @TableName = null, @PrimaryKey = null, @Action = null delete top (1) from TQueue with (rowlock, readpast) output deleted.* into @temp_pop select @TableName = TableName, @PrimaryKey = PrimaryKey, @Action = Action from @temp_pop --================================================ -- do your processing here --================================================ select @TableName, @PrimaryKey, @Action end 

to remove from the queue, you have just completed the procedure.

Hope this helps.

+1
source

Source: https://habr.com/ru/post/1494237/


All Articles