Jump to content

Queue system


KakkArlak

Recommended Posts

Hi,

 

So we have this "advertisement" website / system.

 

The core functionality for the queue and the "vetting" system in the CMS (custom built) ...

 

My question is, for the queue and multiple "operators" (back end users) browsing and vetting ads, what would be the best way to "lock" an advertisement while an operator is viewing it, and possibly editing the details and approving it.?

 

The database classes is built the Zend Framework's component "Zend DB", would Zend Queue be a good option?  (haven't read into it that much).

 

Any help appreciated !

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/205769-queue-system/
Share on other sites

Is your advertisement in a Database or in a File?

 

Either way, you will need a table in a database to use as a Locked File table, eg:

id | advertisement_id | locked | userid | lock_time
unique id | The Advert ID that is locked | True for locked/False for open | The User id of the person who is editing | the time it was locked.

When someone goes to edit the file you would put "locked=true" in the table for that advertisement, Along with the user id that is editing/locked the file and the timestamp that the file was locked.

 

The only problem is if, for instance, a Power-Cut, or simply closing the browser happens, that is not transmitted to the server, so there is no way to know if there was a problem editing the file. This would keep the file locked for ever.

 

For this reason, you will need to set some timer for locked files, and make it so only locked files may be edited. That way if there is a problem the file wont be permanently locked in case of a user locking a file and not being able to access the editing page for some reason (internet down, power cut etc).

 

Hope this helps,

-cb-

Link to comment
https://forums.phpfreaks.com/topic/205769-queue-system/#findComment-1076784
Share on other sites

The only problem is if, for instance, a Power-Cut, or simply closing the browser happens, that is not transmitted to the server, so there is no way to know if there was a problem editing the file. This would keep the file locked for ever.

 

For this reason, you will need to set some timer for locked files, and make it so only locked files may be edited. That way if there is a problem the file wont be permanently locked in case of a user locking a file and not being able to access the editing page for some reason (internet down, power cut etc).

Thanks!

 

Firstly, it's in a MySQL database.

 

I have thought about the whole flag in the database to lock the ad, but the closing the browser thing was an issue.

 

Also, how would I do the timer thing? 

 

Because, I could do that, and then have a cron job that checks for locked ads, and unlocks them.  But what about ads that are currently being viewed by admins..

 

Could unlock them, based on an "user_last_login" field in the "users" table.

 

Come to think of it, that might work best, because the CMS system has a session timeout of 30min, so an admin will be logged out after 30min of inactivity.

 

Then again, Some ads might be kept locked for some time, depending on user logins and whatever.  But theoretically someone closing their browser while viewing an advert would be a small percentage...

Link to comment
https://forums.phpfreaks.com/topic/205769-queue-system/#findComment-1076807
Share on other sites

Well my thoughts for the timer would be:

 

Once a user clicks the "Edit" button for that advert, You insert a row into the locked_ads tables with the current timestamp when the user clicked the edit button. (Obviously use a unique field for the advert id.)

 

Then on the "View adverts for editing" page, it will obviously show wether a file is locked or not, so it can check wether the current timestamp is greater than the locked_ad timestamp + time in seconds until its unlocked.

 

That way you dont need cron jobs etc. And make sure that when you edit the file that it makes sure there is a row in locked_ads table with that advert id and the current user id. If it exists with a different userid then obviously say file is locked.

If the row doesnt exist at all then force them to reload the page (reload the advert file in case of changes).

 

Also this ethods lets you safely "unlock" a file by simply removing that row from the locked_ads table, this would then allow you to edit the advert knowing that no one else can interfere until your finished.

 

-cb-

Link to comment
https://forums.phpfreaks.com/topic/205769-queue-system/#findComment-1076827
Share on other sites

Cool, but currently there's no listing where you click edit, only the top level user, lets call that admin, can see the list and edit any ad it wants to.

 

The 2nd level of users, lets call that "op" (for operator), the log in to the CMS, and can only see one page.  That page fetches 1 ad from the db ( 1st ad that's not approved or deleted yet, date ASC - so it takes from oldest to newest ).

 

That's all good and well, I can loop through that and check which one to get based on the timestamp + x amount of time, but what if "x" amount of time expired, and the same person is still viewing that ad, and the next one gets it as well ?

 

I'm just thinking of what could happen....

Link to comment
https://forums.phpfreaks.com/topic/205769-queue-system/#findComment-1076855
Share on other sites

You should use a single class library (or include function for procedural) for grabbing an advert (or adverts).

 

This way that one library can:

Delete rows where the timer has expired.

Delete rows that have been edited.

Insert new rows when a file is opened.

 

You should mention on the editing page that the user will get x amount of seconds/minutes before the file is unlocked (i would reverse the locked and unlocked, so the file is locked when its free to edit, because you cant edit the file until its locked in the db).

 

And you could use Javascript (Most modern browsers support this - the only ones that dont are most likely on older phones) to show a timer and warn the client that they do not have long to edit the file.

 

Hope this helps,

-cb-

Link to comment
https://forums.phpfreaks.com/topic/205769-queue-system/#findComment-1076866
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.