Skip to content

Commit 62816a8

Browse files
committed
Merge branch 'release/0.1.5'
2 parents 83402b3 + d056c0b commit 62816a8

File tree

18 files changed

+149
-79
lines changed

18 files changed

+149
-79
lines changed

docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ services:
6868
- MYSQL_DATABASE=solana_trade_bot
6969
volumes:
7070
- mysql_data:/var/lib/mysql
71+
- ./mysql:/docker-entrypoint-initdb.d
7172
ports:
7273
- "3307:3306"
7374
command: --default-authentication-plugin=mysql_native_password

example.config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ mysql_url = "mysql+pymysql://root:root@mysql:3306/solana_trade_bot"
4242
redis_url = "redis://redis:6379/0"
4343

4444
[sentry]
45+
enable = true
4546
dsn = ""
4647
traces_sample_rate = 1.0
4748

mysql/init.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- 创建用户并授予权限
2+
CREATE USER IF NOT EXISTS 'root'@'%' IDENTIFIED BY 'root';
3+
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
4+
FLUSH PRIVILEGES;
5+
6+
-- 确保数据库存在
7+
CREATE DATABASE IF NOT EXISTS solana_trade_bot;

pdm.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies = [
1919
"anchorpy>=0.20.1",
2020
"backoff>=2.2.1",
2121
"solana-tx-parser>=0.0.1",
22-
"sentry-sdk>=2.19.0",
22+
"sentry-sdk>=2.21.0",
2323
"cryptography>=44.0.0",
2424
"grpcio>=1.68.1",
2525
"grpcio-tools>=1.68.1",

src/cache/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from cache.auto.raydium_pool import RaydiumPoolCache
99
from common.config import settings
1010
from common.log import logger
11+
from common.prestart import pre_start
1112
from db.redis import RedisClient
12-
from db.session import init_db
1313

1414

1515
class AutoUpdateCacheService:
@@ -87,7 +87,7 @@ async def stop(self):
8787

8888
async def main():
8989
"""主函数"""
90-
init_db()
90+
pre_start()
9191

9292
service = AutoUpdateCacheService()
9393

src/common/config.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
from typing import Any, Literal, cast
88

99
import tomli
10-
from pydantic import BaseModel, ConfigDict, Field, MySQLDsn, RedisDsn, field_validator
10+
from pydantic import (
11+
BaseModel,
12+
ConfigDict,
13+
Field,
14+
MySQLDsn,
15+
RedisDsn,
16+
field_validator,
17+
)
1118
from pydantic.fields import FieldInfo
1219
from pydantic_settings import (
1320
BaseSettings,
@@ -211,6 +218,12 @@ def validate_target_wallet(cls, value: str) -> Pubkey:
211218
return Pubkey.from_string(value)
212219

213220

221+
class SentryConfig(BaseModel):
222+
enable: bool = False
223+
dsn: str = ""
224+
traces_sample_rate: float = 1.0
225+
226+
214227
class Settings(TomlSettings):
215228
model_config = SettingsConfigDict(
216229
env_file_encoding="utf-8",
@@ -226,6 +239,7 @@ class Settings(TomlSettings):
226239
db: DBConfig
227240
log: LogConfig
228241
tg_bot: TgBotConfig
242+
sentry: SentryConfig
229243

230244

231245
class LazySettings:

src/common/log.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Add console handler with custom format
1515
logger.add(
1616
sys.stderr,
17-
format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>",
17+
format="<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>",
1818
level=LOG_LEVEL,
1919
enqueue=True,
2020
)
@@ -24,7 +24,7 @@
2424
log_path.mkdir(exist_ok=True)
2525
logger.add(
2626
log_path / "error.log",
27-
format="{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {name}:{function}:{line} - {message}",
27+
format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {level: <8} | {name}:{function}:{line} - {message}",
2828
level="ERROR",
2929
rotation="1 day",
3030
retention="7 days",

src/common/prestart.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from common.log import logger
2+
from common.sentry import init_sentry as _init_sentry
3+
from db.session import init_db as _init_db
4+
5+
6+
def pre_start(
7+
init_db: bool = True,
8+
init_sentry: bool = True,
9+
):
10+
if init_db:
11+
_init_db()
12+
logger.info("Database initialized")
13+
14+
if init_sentry:
15+
_init_sentry()
16+
logger.info("Sentry initialized")

src/common/sentry.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sentry_sdk
2+
from pydantic import HttpUrl, ValidationError
3+
4+
from common.config import settings
5+
6+
7+
def init_sentry() -> None:
8+
if settings.sentry.enable is False:
9+
return
10+
11+
dsn = settings.sentry.dsn
12+
try:
13+
HttpUrl(dsn)
14+
except ValidationError:
15+
raise ValueError("Invalid Sentry DSN, must be a valid URL")
16+
traces_sample_rate = settings.sentry.traces_sample_rate
17+
sentry_sdk.init(dsn=dsn, traces_sample_rate=traces_sample_rate)

0 commit comments

Comments
 (0)