Rev 4016 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/python'''If a order has been in the payment pending state for morethan 2 days, it marks it as failed.Created on 09-Aug-2011@author: chandranshu'''import datetimeimport optparseimport sysif __name__ == '__main__' and __package__ is None:import ossys.path.insert(0, os.getcwd())from shop2020.thriftpy.model.v1.order.ttypes import OrderStatusfrom shop2020.model.v1.order.impl import DataServicefrom shop2020.model.v1.order.impl.DataService import Orderfrom elixir import sessiondef move_payment_pending_orders_to_failed_state(days, db_hostname):DataService.initialize(db_hostname=db_hostname, echoOn=True)current_time = datetime.datetime.now()to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)to_datetime = to_datetime - datetime.timedelta(days)orders = Order.query.filter_by(status=OrderStatus.PAYMENT_PENDING).filter(Order.created_timestamp <= to_datetime).all()for order in orders:order.status = OrderStatus.PAYMENT_FAILEDsession.commit()def main():parser = optparse.OptionParser()parser.add_option("-d", "--days", dest="days",default=2, type="int",help="move orders in the PAYMENT_PENDING state for more than NUM days to PAYMENT_FAILED state",metavar="NUM")parser.add_option("-H", "--host", dest="hostname",default="localhost",type="string", help="The HOST where the DB server is running",metavar="HOST")(options, args) = parser.parse_args()if len(args) != 0:parser.error("You've supplied extra arguments. Are you sure you want to run this program?")move_payment_pending_orders_to_failed_state(options.days, options.hostname)if __name__ == '__main__':main()