MiniVend Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

Re: [mv] file locking



Quoting B.J. Bezemer (bas.bezemer@wxs.nl):
> 
> Is there a method to read from and write to a gdbm-database used by
> minivend, by a perl script without disturbing the minivend process?
> 
> I'm using an external payment system from my shop. The payment system sends
> me a confirmation email on whether the payment was succesfull including
> order number and other details. I want to make a perl script that
> periodically checks the messages in my mail box, verify them with the open
> orders in a gdbm/minivend-database, and, if the order is legitimate, change
> the status of the order.
> 
> For secure operation, I want to include some type of file locking (flock or
> something), but I can't seem to figure out how minivend does such a thing.
> 

SQL is best for this type of thing, but it can be done.

GDBM has built-in locking, but it isn't real good. Open in write mode,
and MiniVend will hold off (for a while) before opening the database.
If it is a table used only for that purpose then it should be OK. 

NOTE: MiniVend won't wait long; for a database hotspot could really
bring down the server. Get in and get out fast, as GDBM doesn't unlock
very well. Your users will get a server error if they try to open the
table while you have it open.

But by far it is easiest to use a MiniVend page:

[tag flag write]transaction[/tag]

[if type=data term="transaction::valid::[data session arg]"]
	Order [data session arg] found.
	[data	table=transaction
			column=order_complete
			key="[data session arg]"
			value=1]
[else]
	Order [data session arg] not found.
[/else]

[/if]
[if type=data term="transaction::order_complete::[data session arg]"]
	Order [data session arg] completed.
[else]
	Order [data session arg] update failed.
[/else]
[/if]

Then simply call it from an external script like:

#!/usr/bin/perl

use LWP::Simple;

$order_number = '002438';
$string = get("http://www.minivend.com/cgi-bin/simple/the_page?;$order_number");

if($string =~ /completed/) {
	print "Order $order_number flagged as complete.";
}
else {
	print "UPDATE FAILED: $string";
}

Authenticating the transaction via HTTP basic authentication and MiniVend's
access control is left as an exercise for the reader.

-- 
Mike Heins                          http://www.minivend.com/  ___ 
                                    Internet Robotics        |_ _|____
Any man who is under 30, and is     131 Willow Lane, Floor 2  | ||  _ \
not liberal, has not heart; and     Oxford, OH  45056         | || |_) |
any man who is over 30, and is not  <mikeh@minivend.com>     |___|  _ <
a conservative, has not brains.     513.523.7621 FAX 7501        |_| \_\
 -- Winston Churchill              


Search for: Match: Format: Sort by: