views:

38

answers:

2

I'm working on a web application that automates a reservation process using the Google Calendar API and PHP. When the user first selects a date, my script creates a "tentative" event on the Calendar to prevent other users from trying to select the same date. However, to avoid the proliferation of tentative dates created by users that don't follow through, I want to impose a time limit on the transaction process, so that if the user leaves the app or takes too long, the tentative date will be removed from the calendar (and thus available for other users to reserve).

We're currently storing the appointments in a MySQL db as well as the Google Cal, so here's my current strategy: when the tentative appointment is first created, store the tentative appointment in the db with a timestamp. Then, schedule a cron job (maybe every hour or so) that scans through the database and removes tentative reservations based on the age of their timestamp (removing them from both the db and the google cal).

In theory, this should work. However, my question is this: is there a simpler/more elegant way to do this that I'm not thinking of? Does anyone have a better solution to this problem?

A: 

When someone tries to create an appointment at the same time as a tentative appointment, check to see if the tentative appointment is "too old". If it is: delete it and create the new one. If it isn't: tell the user an appointment is already being created at that time.

rojoca
I actually considered this solution... it's workable, but the downside is that it doesn't prevent the Google Calendar from being cluttered up with dead tentative appointments that nobody's attempted to overwrite. Still, a good suggestion, and perhaps I could implement it alongside my current strategy.
Matt
+1  A: 

Not sure if this is "better", but if the primary goal is limiting clutter you could cap the number of tentative events during a given time period and have your cron job delete all but the newest N during each period. This way the calendar can't get choked if you have a sudden rush of tentative events, but you can keep them around longer when there's less activity giving people a larger window to confirm their reservation during slow periods.

bemace