| Line 17... |
Line 17... |
| 17 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus
|
17 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus
|
| 18 |
from shop2020.model.v1.order.impl import DataService
|
18 |
from shop2020.model.v1.order.impl import DataService
|
| 19 |
from shop2020.model.v1.order.impl.DataService import Order
|
19 |
from shop2020.model.v1.order.impl.DataService import Order
|
| 20 |
from elixir import session
|
20 |
from elixir import session
|
| 21 |
|
21 |
|
| 22 |
def move_payment_pending_orders_to_failed_state(days):
|
22 |
def move_payment_pending_orders_to_failed_state(days, db_hostname):
|
| 23 |
DataService.initialize('transaction')
|
23 |
DataService.initialize(db_hostname=db_hostname, echoOn=True)
|
| 24 |
current_time = datetime.datetime.now()
|
24 |
current_time = datetime.datetime.now()
|
| 25 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
25 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 26 |
to_datetime = to_datetime - datetime.timedelta(days)
|
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()
|
27 |
orders = Order.query.filter_by(status=OrderStatus.PAYMENT_PENDING).filter(Order.created_timestamp <= to_datetime).all()
|
| 28 |
for order in orders:
|
28 |
for order in orders:
|
| Line 33... |
Line 33... |
| 33 |
parser = optparse.OptionParser()
|
33 |
parser = optparse.OptionParser()
|
| 34 |
parser.add_option("-d", "--days", dest="days",
|
34 |
parser.add_option("-d", "--days", dest="days",
|
| 35 |
default=2, type="int",
|
35 |
default=2, type="int",
|
| 36 |
help="move orders in the PAYMENT_PENDING state for more than NUM days to PAYMENT_FAILED state",
|
36 |
help="move orders in the PAYMENT_PENDING state for more than NUM days to PAYMENT_FAILED state",
|
| 37 |
metavar="NUM")
|
37 |
metavar="NUM")
|
| - |
|
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")
|
| 38 |
(options, args) = parser.parse_args()
|
42 |
(options, args) = parser.parse_args()
|
| 39 |
if len(args) != 0:
|
43 |
if len(args) != 0:
|
| 40 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
44 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
| 41 |
move_payment_pending_orders_to_failed_state(options.days)
|
45 |
move_payment_pending_orders_to_failed_state(options.days, options.hostname)
|
| 42 |
|
46 |
|
| 43 |
if __name__ == '__main__':
|
47 |
if __name__ == '__main__':
|
| 44 |
main()
|
48 |
main()
|
| 45 |
|
49 |
|