CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 10s
CI / test (push) Successful in 1m46s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
The task registry was module-global, so tasks registered by an app with federation enabled would also run under an app without it (and break the "federation off registers nothing" guarantee depending on order). Tasks now live on each app (app.extensions["worker_tasks"]); register_task/register_periodic take the app, and the worker runs the current app's tasks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
"""Self-hosted, Last.fm-compatible music scrobbling service."""
|
|
|
|
from importlib.metadata import PackageNotFoundError, version
|
|
|
|
try:
|
|
__version__ = version("scrobby") # distribution name; set from the release tag at build time
|
|
except PackageNotFoundError: # running from a source tree without installing
|
|
__version__ = "0.0.0+unknown"
|
|
|
|
|
|
def create_app(config_object=None):
|
|
from flask import Flask
|
|
|
|
from scrobbler import models # noqa: F401 (register models with SQLAlchemy)
|
|
from scrobbler.config import Config
|
|
from scrobbler.extensions import db, migrate
|
|
from scrobbler.metrics import http as http_metrics
|
|
|
|
app = Flask(__name__, static_folder=None) # API only: the UI is hosted separately
|
|
app.config.from_object(config_object or Config)
|
|
|
|
db.init_app(app)
|
|
migrate.init_app(app, db, directory=_migrations_dir())
|
|
http_metrics.init_app(app)
|
|
|
|
from flask_cors import CORS
|
|
|
|
from scrobbler import api
|
|
from scrobbler.lastfm import bp as lastfm_bp
|
|
|
|
app.register_blueprint(lastfm_bp)
|
|
api.init_app(app)
|
|
|
|
from scrobbler import federation # the only place the core touches federation
|
|
|
|
federation.init_app(app)
|
|
CORS(
|
|
app,
|
|
resources={r"/api/v1/*": {"origins": app.config["CORS_ORIGINS"]}},
|
|
allow_headers=["Authorization", "Content-Type"],
|
|
max_age=600,
|
|
)
|
|
|
|
from scrobbler.cli import imports_cli, worker_command
|
|
from scrobbler.services import imports as import_service
|
|
|
|
app.cli.add_command(worker_command)
|
|
app.cli.add_command(imports_cli)
|
|
import_service.register_worker_tasks(app)
|
|
|
|
from scrobbler.metrics import db as db_metrics
|
|
|
|
with app.app_context():
|
|
db_metrics.instrument(db.engine)
|
|
|
|
if app.config["START_METRICS_SERVER"]:
|
|
from scrobbler.metrics.server import start_metrics_server
|
|
|
|
start_metrics_server(app.config["METRICS_PORT"], app.config["SQLALCHEMY_DATABASE_URI"])
|
|
|
|
return app
|
|
|
|
|
|
def _migrations_dir() -> str:
|
|
from pathlib import Path
|
|
|
|
return str(Path(__file__).resolve().parent / "migrations")
|