| Line 11... |
Line 11... |
| 11 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus
|
11 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus
|
| 12 |
from shop2020.model.v1.order.impl import DataService
|
12 |
from shop2020.model.v1.order.impl import DataService
|
| 13 |
from shop2020.model.v1.order.impl.DataService import Order
|
13 |
from shop2020.model.v1.order.impl.DataService import Order
|
| 14 |
from elixir import session
|
14 |
from elixir import session
|
| 15 |
|
15 |
|
| 16 |
def move_out_of_stock_orders_to_pending_queue(days):
|
16 |
def move_out_of_stock_orders_to_pending_queue(days, db_hostname):
|
| 17 |
DataService.initialize('transaction')
|
17 |
DataService.initialize(db_hostname=db_hostname, echoOn=True)
|
| 18 |
current_time = datetime.datetime.now()
|
18 |
current_time = datetime.datetime.now()
|
| 19 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
19 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 20 |
to_datetime = to_datetime - datetime.timedelta(days-1)
|
20 |
to_datetime = to_datetime - datetime.timedelta(days-1)
|
| 21 |
from_datetime = to_datetime - datetime.timedelta(1)
|
21 |
from_datetime = to_datetime - datetime.timedelta(1)
|
| 22 |
orders = Order.query.filter_by(status=OrderStatus.INVENTORY_LOW).filter(Order.outofstock_timestamp >= from_datetime).filter(Order.outofstock_timestamp <= to_datetime).all()
|
22 |
orders = Order.query.filter_by(status=OrderStatus.INVENTORY_LOW).filter(Order.outofstock_timestamp >= from_datetime).filter(Order.outofstock_timestamp <= to_datetime).all()
|
| Line 28... |
Line 28... |
| 28 |
parser = optparse.OptionParser()
|
28 |
parser = optparse.OptionParser()
|
| 29 |
parser.add_option("-d", "--days", dest="days",
|
29 |
parser.add_option("-d", "--days", dest="days",
|
| 30 |
default=2, type="int",
|
30 |
default=2, type="int",
|
| 31 |
help="move orders marked as out of stock in last NUM days",
|
31 |
help="move orders marked as out of stock in last NUM days",
|
| 32 |
metavar="NUM")
|
32 |
metavar="NUM")
|
| - |
|
33 |
parser.add_option("-H", "--host", dest="hostname",
|
| - |
|
34 |
default="localhost",
|
| - |
|
35 |
type="string", help="The HOST where the DB server is running",
|
| - |
|
36 |
metavar="HOST")
|
| 33 |
(options, args) = parser.parse_args()
|
37 |
(options, args) = parser.parse_args()
|
| 34 |
if len(args) != 0:
|
38 |
if len(args) != 0:
|
| 35 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
39 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
| 36 |
move_out_of_stock_orders_to_pending_queue(options.days)
|
40 |
move_out_of_stock_orders_to_pending_queue(options.days, options.hostname)
|
| 37 |
|
41 |
|
| 38 |
if __name__ == '__main__':
|
42 |
if __name__ == '__main__':
|
| 39 |
main()
|
43 |
main()
|
| 40 |
|
44 |
|