-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4e6cec
commit 260e89c
Showing
9 changed files
with
22 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ | |
|
||
class WarriorsConfig(AppConfig): | ||
name = "warriors" | ||
|
||
def ready(self): | ||
import warriors.scheduler # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,15 @@ | ||
import logging | ||
import sched | ||
from datetime import timedelta | ||
|
||
from django_scheduler.models import register_job | ||
|
||
from .challenge_matchmaking import schedule_losing_battle_top | ||
from .rating_models import update_rating | ||
from .stats import create_arena_stats | ||
from .tasks import schedule_battle, schedule_battles_top | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Scheduler(sched.scheduler): | ||
def enter_recurring(self, delay, priority, action, argument=(), kwargs={}): | ||
action(*argument, **kwargs) | ||
self.enter(delay, priority, self.enter_recurring, (delay, priority, action, argument, kwargs)) | ||
|
||
def run(self, *args, **kwargs): | ||
logger.info('Starting scheduler') | ||
return super().run(*args, **kwargs) | ||
|
||
def clear(self): | ||
logger.info('Clearing scheduler') | ||
with self._lock: | ||
self._queue.clear() | ||
|
||
|
||
scheduler = Scheduler() | ||
scheduler.enter_recurring(1, 0, schedule_battle) | ||
scheduler.enter_recurring(60 * 10, 0, schedule_battles_top) | ||
scheduler.enter_recurring(60, 0, update_rating) | ||
scheduler.enter_recurring(60 * 60, 0, create_arena_stats) | ||
scheduler.enter_recurring(60 * 10, 0, schedule_losing_battle_top) | ||
register_job(schedule_battle, timedelta(seconds=1)) | ||
register_job(schedule_battles_top, timedelta(minutes=10)) | ||
register_job(update_rating, timedelta(minutes=1)) | ||
register_job(create_arena_stats, timedelta(hours=1)) | ||
register_job(schedule_losing_battle_top, timedelta(minutes=10)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters