-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor cronjobs as a separate service
- Loading branch information
Carlos Wu Fei
authored and
Carlos Wu Fei
committed
Nov 21, 2023
1 parent
1e70634
commit a60dcd0
Showing
9 changed files
with
130 additions
and
68 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM ubuntu:latest | ||
RUN apt-get update && apt-get install -y --no-install-recommends python3-pip build-essential python3-dev python-setuptools | ||
COPY api api | ||
WORKDIR api | ||
RUN pip3 install pipenv --no-cache-dir --upgrade | ||
RUN pipenv install --system --deploy --ignore-pipfile --clear | ||
ENTRYPOINT ["python3", "-u", "cronjobs.py"] | ||
|
||
STOPSIGNAL SIGTERM |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import atexit | ||
import logging | ||
import time | ||
import asyncio | ||
|
||
from apscheduler.schedulers.blocking import BlockingScheduler | ||
from account.assets import Assets | ||
|
||
|
||
logging.Formatter.converter = time.gmtime # date time in GMT/UTC | ||
logging.basicConfig( | ||
level=logging.INFO, | ||
filename=None, | ||
format="%(asctime)s.%(msecs)03d UTC %(levelname)s %(name)s: %(message)s", | ||
datefmt="%Y-%m-%d %H:%M:%S", | ||
) | ||
|
||
def main(): | ||
|
||
scheduler = BlockingScheduler() | ||
assets = Assets() | ||
timezone = "Europe/London" | ||
|
||
scheduler.add_job( | ||
func=assets.store_balance, | ||
trigger="cron", | ||
timezone=timezone, | ||
hour=1, | ||
minute=1, | ||
id="store_balance", | ||
) | ||
scheduler.add_job( | ||
func=assets.disable_isolated_accounts, | ||
trigger="cron", | ||
timezone=timezone, | ||
hour=2, | ||
minute=1, | ||
id="disable_isolated_accounts", | ||
) | ||
scheduler.add_job( | ||
func=assets.clean_balance_assets, | ||
trigger="cron", | ||
timezone=timezone, | ||
hour=3, | ||
minute=1, | ||
id="clean_balance_assets", | ||
) | ||
scheduler.start() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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