Skip to content

Commit

Permalink
Skiped days and stream registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Leits committed Oct 21, 2015
1 parent 7b48490 commit e1c1bbd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
24 changes: 17 additions & 7 deletions openprocurement/chronograph/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,14 @@ def planning_auction(tender, start, db, quick=False, lot_id=None):
#_, dayStream = get_date(db, mode, date.date())
#set_date(db, mode, date.date(), WORKING_DAY_END, dayStream+1)
set_date(db, plan, end.time(), stream, "_".join([tid, lot_id]) if lot_id else tid, dayStart)
return start
return (start, stream)


def skipped_days(days):
days_str = ''
if days:
days_str = ' Skipped {} full days.'.format(days)
return days_str


def check_tender(tender, db):
Expand Down Expand Up @@ -165,11 +172,12 @@ def check_tender(tender, db):
quick = os.environ.get('SANDBOX_MODE', False) and u'quick' in tender.get('submissionMethodDetails', '')
while not planned:
try:
auctionPeriod = planning_auction(tender, tenderPeriodEnd, db, quick)
auctionPeriod, stream = planning_auction(tender, tenderPeriodEnd, db, quick)
planned = True
except ResourceConflict:
planned = False
auctionPeriod = randomize(auctionPeriod).isoformat()
days = skipped_days(skip_days)
LOG.info('Planned auction for tender {} to {}'.format(tender['id'], auctionPeriod))
return {'auctionPeriod': {'startDate': auctionPeriod}}, now
elif tender.get('lots') and tender['status'] == 'active.tendering' and not tender.get('auctionPeriod') and tenderPeriodEnd and tenderPeriodEnd > now:
Expand All @@ -183,7 +191,7 @@ def check_tender(tender, db):
planned = False
while not planned:
try:
auctionPeriod = planning_auction(tender, tenderPeriodEnd, db, quick, lot_id)
auctionPeriod, stream = planning_auction(tender, tenderPeriodEnd, db, quick, lot_id)
planned = True
except ResourceConflict:
planned = False
Expand Down Expand Up @@ -211,11 +219,12 @@ def check_tender(tender, db):
quick = os.environ.get('SANDBOX_MODE', False) and u'quick' in tender.get('submissionMethodDetails', '')
while not planned:
try:
auctionPeriod = planning_auction(tender, tenderPeriodEnd, db, quick)
auctionPeriod, stream = planning_auction(tender, tenderPeriodEnd, db, quick)
planned = True
except ResourceConflict:
planned = False
auctionPeriod = randomize(auctionPeriod).isoformat()
days = skipped_days(skip_days)
LOG.info('Planned auction for tender {} to {}'.format(tender['id'], auctionPeriod))
return {'auctionPeriod': {'startDate': auctionPeriod}}, now
elif not tender.get('lots') and tender['status'] == 'active.auction' and tender.get('auctionPeriod'):
Expand All @@ -226,11 +235,12 @@ def check_tender(tender, db):
quick = os.environ.get('SANDBOX_MODE', False) and u'quick' in tender.get('submissionMethodDetails', '')
while not planned:
try:
auctionPeriod = planning_auction(tender, now, db, quick)
auctionPeriod, stream = planning_auction(tender, now, db, quick)
planned = True
except ResourceConflict:
planned = False
auctionPeriod = randomize(auctionPeriod).isoformat()
days = skipped_days(skip_days)
LOG.info('Replanned auction for tender {} to {}'.format(tender['id'], auctionPeriod))
return {'auctionPeriod': {'startDate': auctionPeriod}}, now
else:
Expand All @@ -246,7 +256,7 @@ def check_tender(tender, db):
planned = False
while not planned:
try:
auctionPeriod = planning_auction(tender, tenderPeriodEnd, db, quick, lot_id)
auctionPeriod,stream = planning_auction(tender, tenderPeriodEnd, db, quick, lot_id)
planned = True
except ResourceConflict:
planned = False
Expand All @@ -269,7 +279,7 @@ def check_tender(tender, db):
planned = False
while not planned:
try:
auctionPeriod = planning_auction(tender, now, db, quick, lot_id)
auctionPeriod, stream = planning_auction(tender, now, db, quick, lot_id)
planned = True
except ResourceConflict:
planned = False
Expand Down
10 changes: 5 additions & 5 deletions openprocurement/chronograph/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,25 +444,25 @@ def test_auction_quick_planning(self):

def test_auction_planning_overlow(self):
now = datetime.now(TZ)
res = planning_auction(test_tender_data_test_quick, now, self.db)
res = planning_auction(test_tender_data_test_quick, now, self.db)[0]
startDate = res.date()
count = 0
while startDate == res.date():
count += 1
res = planning_auction(test_tender_data_test_quick, now, self.db)
res = planning_auction(test_tender_data_test_quick, now, self.db)[0]
self.assertEqual(count, 100)

def test_auction_planning_buffer(self):
some_date = datetime(2015, 9, 21, 6, 30)
date = some_date.date()
ndate = (some_date + timedelta(days=1)).date()
res = planning_auction(test_tender_data_test_quick, some_date, self.db)
res = planning_auction(test_tender_data_test_quick, some_date, self.db)[0]
self.assertEqual(res.date(), date)
some_date = some_date.replace(hour=10)
res = planning_auction(test_tender_data_test_quick, some_date, self.db)
res = planning_auction(test_tender_data_test_quick, some_date, self.db)[0]
self.assertNotEqual(res.date(), date)
self.assertEqual(res.date(), ndate)
some_date = some_date.replace(hour=16)
res = planning_auction(test_tender_data_test_quick, some_date, self.db)
res= planning_auction(test_tender_data_test_quick, some_date, self.db)[0]
self.assertNotEqual(res.date(), date)
self.assertEqual(res.date(), ndate)

0 comments on commit e1c1bbd

Please sign in to comment.