-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add apscheduler - reorder scheduling process
- Loading branch information
1 parent
aaa4707
commit 541add5
Showing
41 changed files
with
1,409 additions
and
827 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ whoosh~=2.7.4 | |
jieba>=0.42.1 | ||
starlette>=0.37.2 | ||
jinja2~=3.1.3 | ||
apscheduler~=3.10.4 |
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
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 |
---|---|---|
|
@@ -6,4 +6,6 @@ | |
files, | ||
account, | ||
statistic, | ||
self_hosted, | ||
notice, | ||
) |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from . import tasks | ||
from . import timing | ||
from .base import ( | ||
start, | ||
stop, | ||
run_once_at, | ||
run_once_after, | ||
run_once_now, | ||
run_every_at, | ||
) |
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 |
---|---|---|
@@ -0,0 +1,115 @@ | ||
from datetime import datetime, timedelta | ||
from typing import Callable, Optional, Tuple, Dict, Any | ||
|
||
from apscheduler.schedulers.background import BackgroundScheduler | ||
|
||
""" | ||
- BlockingScheduler: | ||
use when the scheduler is the only thing running in your process | ||
- BackgroundScheduler: | ||
use when you’re not using any of the frameworks below, | ||
and want the scheduler to run in the background inside your application | ||
- AsyncIOScheduler: | ||
use if your application uses the asyncio module | ||
- GeventScheduler: | ||
use if your application uses gevent | ||
- TornadoScheduler: | ||
use if you’re building a Tornado application | ||
- TwistedScheduler: | ||
use if you’re building a Twisted application | ||
- QtScheduler: | ||
use if you’re building a Qt application | ||
""" | ||
|
||
# a separate thread | ||
_scheduler = BackgroundScheduler() | ||
|
||
|
||
def start(): | ||
_scheduler.start() | ||
|
||
|
||
def stop(): | ||
_scheduler.shutdown() | ||
|
||
|
||
def _get_default(args, kwargs): | ||
if args is None: | ||
args = () | ||
if kwargs is None: | ||
kwargs = {} | ||
return args, kwargs | ||
|
||
|
||
def run_once_at( | ||
func: Callable, | ||
time: datetime, | ||
args: Optional[Tuple] = None, | ||
kwargs: Optional[Dict[str, Any]] = None, | ||
): | ||
args, kwargs = _get_default(args, kwargs) | ||
_scheduler.add_job( | ||
func=func, | ||
trigger="date", | ||
run_date=time, | ||
args=args, | ||
kwargs=kwargs, | ||
) | ||
|
||
|
||
def run_once_now( | ||
func: Callable, | ||
args: Optional[Tuple] = None, | ||
kwargs: Optional[Dict[str, Any]] = None, | ||
): | ||
return run_once_at(func=func, time=datetime.now(), args=args, kwargs=kwargs) | ||
|
||
|
||
def run_once_after( | ||
func: Callable, | ||
second: float, | ||
args: Optional[Tuple] = None, | ||
kwargs: Optional[Dict[str, Any]] = None, | ||
): | ||
return run_once_at( | ||
func=func, | ||
time=datetime.now() + timedelta(seconds=second), | ||
args=args, | ||
kwargs=kwargs, | ||
) | ||
|
||
|
||
def run_every_at( | ||
func: Callable, | ||
second: Optional[int] = None, | ||
minute: Optional[int] = None, | ||
hour: Optional[int] = None, | ||
day: Optional[int] = None, | ||
month: Optional[int] = None, | ||
day_of_week: Optional[int] = None, | ||
start_date: Optional[datetime] = None, | ||
end_date: Optional[datetime] = None, | ||
args: Optional[Tuple] = None, | ||
kwargs: Optional[Dict[str, Any]] = None, | ||
): | ||
args, kwargs = _get_default(args, kwargs) | ||
_scheduler.add_job( | ||
func=func, | ||
trigger="cron", | ||
second=second, | ||
minute=minute, | ||
hour=hour, | ||
day=day, | ||
month=month, | ||
day_of_week=day_of_week, | ||
start_date=start_date, | ||
end_date=end_date, | ||
args=args, | ||
kwargs=kwargs, | ||
) |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import ( | ||
test, | ||
email, | ||
) |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def print_test(txt: str): | ||
print(f"test and print '{txt}'") |
File renamed without changes.
Oops, something went wrong.