Subversion Repositories SmartDukaan

Rev

Rev 2879 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2879 chandransh 1
#!/usr/bin/python
2
 
3
'''
4
Created on 09-Aug-2011
5
 
6
@author: chandranshu
7
'''
8
 
9
import datetime
10
import optparse
11
import sys
12
 
13
if __name__ == '__main__' and __package__ is None:
14
    import os
15
    sys.path.insert(0, os.getcwd())
16
 
17
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus
18
from shop2020.model.v1.order.impl import DataService
19
from shop2020.model.v1.order.impl.DataService import Order
20
from elixir import session
21
 
4016 chandransh 22
def move_payment_pending_orders_to_failed_state(days, db_hostname):
23
    DataService.initialize(db_hostname=db_hostname, echoOn=True)
2879 chandransh 24
    current_time = datetime.datetime.now()
25
    to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
26
    to_datetime = to_datetime - datetime.timedelta(days)
27
    orders = Order.query.filter_by(status=OrderStatus.PAYMENT_PENDING).filter(Order.created_timestamp <= to_datetime).all()
28
    for order in orders:
29
        order.status = OrderStatus.PAYMENT_FAILED
30
    session.commit()
31
 
32
def main():
33
    parser = optparse.OptionParser()
34
    parser.add_option("-d", "--days", dest="days",
35
                   default=2, type="int",
36
                   help="move orders in the PAYMENT_PENDING state for more than NUM days to PAYMENT_FAILED state",
37
                   metavar="NUM")
4016 chandransh 38
    parser.add_option("-H", "--host", dest="hostname",
39
                      default="localhost",
40
                      type="string", help="The HOST where the DB server is running",
41
                      metavar="HOST")
2879 chandransh 42
    (options, args) = parser.parse_args()
43
    if len(args) != 0:
44
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
4016 chandransh 45
    move_payment_pending_orders_to_failed_state(options.days, options.hostname)
2879 chandransh 46
 
47
if __name__ == '__main__':
48
    main()