-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues #12, #16, #17 #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import time | ||
from . import SKIP_DYNAMIC_BMS | ||
from .trigger import Trigger | ||
from .. import exceptions | ||
from ..log import log | ||
from bookied_sync.event import LookupEvent | ||
from datetime import datetime | ||
|
||
|
||
class CreateTrigger(Trigger): | ||
""" This trigger inherits class:`Trigger` and deals with create incidents | ||
that are fired by the data proxy when new events are announced. | ||
|
@@ -40,11 +42,15 @@ def _trigger(self, args): | |
self.event.update() | ||
|
||
# Create Betting market Groups | ||
self.createBmgs() | ||
status = self.createBmgs() | ||
|
||
return True | ||
if status == 'midway': | ||
return status | ||
else: | ||
return True | ||
|
||
def createBmgs(self): | ||
tic = time.time() | ||
""" Go through all Betting Market groups and create them | ||
""" | ||
for bmg in self.event.bettingmarketgroups: | ||
|
@@ -53,32 +59,48 @@ def createBmgs(self): | |
uialist = list() | ||
uialist = bmg["asset"] | ||
name = bmg["description"]["en"] | ||
x = 0 | ||
x = 0 | ||
while x < len(uialist): | ||
bmg["asset"] = uialist[x] | ||
bmg["asset"] = uialist[x] | ||
if(len(uialist) > 1): | ||
bmg["description"]["en"] = name + "_" + str(bmg["asset"]) | ||
# To avoid duplicate BMG's on retriggering replays from DP's | ||
if "id" in bmg: | ||
bmg["id"] = None | ||
bmg["description"]["en"] = name + "_" + str(bmg["asset"]) | ||
# To avoid duplicate BMG's on retriggering replays from DP's | ||
if "id" in bmg: | ||
bmg["id"] = None | ||
|
||
x += 1 | ||
# Skip dynamic bmgs | ||
if bmg["dynamic"]: | ||
# Dynamic BMGs are created separately | ||
log.debug("Skipping dynamic BMG: {}".format(str(bmg.identifier))) | ||
continue | ||
# Dynamic BMGs are created separately | ||
log.debug("Skipping dynamic BMG: {}".format(str(bmg.identifier))) | ||
continue | ||
bmg.update() | ||
self.createBms(bmg) | ||
statusCreateBms = self.createBms(bmg) | ||
if statusCreateBms == "midway": | ||
print("createBmms, toc > 10") | ||
return 'midway' | ||
|
||
# Terminate loop and return midway if bmg creation took time. | ||
# So that incident is processed later. | ||
toc = time.time() - tic | ||
if toc > 30: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any criteria for selecting 30 secs over here, levee a comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If timeout is less than 30, a soccer event and all it's betting markets creation takes more than two attempts. With 30 or more number of attempts is 2, which is the lowest possible. Any attempt to get a soccer event created with single attempt consumes about 12 minutes if time out removed. Hence taking take into consideration soccer events, 30 seconds is an optimal timout for bmg creation. |
||
return 'midway' | ||
|
||
def createBms(self, bmg): | ||
""" Go through all betting markets and create them | ||
""" | ||
tic = time.time() | ||
for bm in bmg.bettingmarkets: | ||
|
||
log.debug( | ||
"Updating Betting Market {} ...".format(bm["description"].get("en")) | ||
) | ||
bm.update() | ||
# break the loop and return midway if bm creation takes time. | ||
toc = time.time() | ||
if (toc - tic) > 10: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any criteria for selecting 30 secs over here, levee a comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is decided based on soccer events. For soccer, the first bmg has six bms. There are cases where sometimes creation of one bm takes about 30 seconds, that an rq time out is reached before the bmg for loop timeout. It's natural to take about 3 seconds for creation of a bm and 30 seconds is not acceptable. Decided somewhere in the middle, 10 seconds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, makes sense |
||
return "midway" | ||
tic = toc | ||
|
||
def getIncidentEvent(self): | ||
""" Does not throw in all cases but returns None in case of error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the purpose is to cancel and delete one by one from the list. Could you delete everything without cancel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q doesn't have a method dequeue associated with it and things worked well with delete.