-
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.
Merge pull request #636 from SUNET/ylle-account-checker
Ylle-account-checker
- Loading branch information
Showing
27 changed files
with
620 additions
and
32 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 |
---|---|---|
|
@@ -76,4 +76,7 @@ | |
"Werkzeug", | ||
"zxcvbn" | ||
], | ||
"mypy-type-checker.args": [ | ||
"--ignore-missing-imports" | ||
], | ||
} |
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,3 +1,4 @@ | ||
-r main.in | ||
-c main.txt | ||
jinja2 | ||
apscheduler<4 # Next major version has API breaking changes |
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 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
Empty file.
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,51 @@ | ||
import logging | ||
from datetime import datetime | ||
from enum import Enum | ||
from typing import Optional | ||
|
||
import pymongo | ||
|
||
from eduid.userdb.db.base import TUserDbDocument | ||
from eduid.userdb.identity import IdentityType | ||
from eduid.userdb.meta import CleanerType | ||
from eduid.userdb.user import User | ||
from eduid.userdb.userdb import UserDB, UserVar | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class CleanerQueueUser(User): | ||
""" | ||
User version to bookkeep cleaning actions. | ||
eppn | ||
cleaner_type | ||
""" | ||
|
||
cleaner_type: CleanerType | ||
|
||
|
||
class CleanerQueueDB(UserDB[CleanerQueueUser]): | ||
def __init__(self, db_uri: str, db_name: str = "eduid_user_cleaner", collection: str = "cleaner_queue"): | ||
super().__init__(db_uri, db_name, collection) | ||
|
||
indexes = { | ||
"eppn-index-v1": {"key": [("eduPersonPrincipalName", 1)], "unique": True}, | ||
"creation-index-v1": {"key": [("meta.created_ts", 1)], "unique": False}, | ||
} | ||
self.setup_indexes(indexes) | ||
|
||
@classmethod | ||
def user_from_dict(cls, data: TUserDbDocument) -> CleanerQueueUser: | ||
return CleanerQueueUser.from_dict(data) | ||
|
||
def get_next_user(self, cleaner_type: CleanerType) -> Optional[CleanerQueueUser]: | ||
doc = self._coll.find_one_and_delete( | ||
filter={"cleaner_type": cleaner_type}, sort=[("meta.created_ts", pymongo.ASCENDING)] | ||
) | ||
if doc is not None: | ||
logger.debug("Found document") | ||
user = self.user_from_dict(doc) | ||
return user | ||
else: | ||
logger.debug("No document found") | ||
return None |
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,16 @@ | ||
from eduid.userdb.db.base import TUserDbDocument | ||
from eduid.userdb.user import User | ||
from eduid.userdb.userdb import UserDB | ||
|
||
|
||
class CleanerUser(User): | ||
pass | ||
|
||
|
||
class CleanerUserDB(UserDB[CleanerUser]): | ||
def __init__(self, db_uri: str, db_name: str = "eduid_user_cleaner", collection: str = "profiles"): | ||
super().__init__(db_uri, db_name, collection) | ||
|
||
@classmethod | ||
def user_from_dict(cls, data: TUserDbDocument) -> CleanerUser: | ||
return CleanerUser.from_dict(data) |
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
Empty file.
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,45 @@ | ||
from contextlib import asynccontextmanager | ||
from typing import Callable, Optional | ||
|
||
from fastapi import FastAPI | ||
|
||
from eduid.common.config.parsers import load_config | ||
from eduid.workers.job_runner.config import JobRunnerConfig | ||
from eduid.workers.job_runner.context import Context | ||
from eduid.workers.job_runner.scheduler import JobScheduler | ||
from eduid.workers.job_runner.status import status_router | ||
|
||
|
||
class JobRunner(FastAPI): | ||
scheduler: JobScheduler = JobScheduler(timezone="UTC") | ||
|
||
def __init__( | ||
self, name: str = "job_runner", test_config: Optional[dict] = None, lifespan: Optional[Callable] = None | ||
): | ||
self.config = load_config(typ=JobRunnerConfig, app_name=name, ns="worker", test_config=test_config) | ||
super().__init__(root_path=self.config.application_root, lifespan=lifespan) | ||
|
||
self.context = Context(config=self.config) | ||
self.context.logger.info(f"Starting {name} worker: {self.context.worker_name}") | ||
|
||
|
||
@asynccontextmanager | ||
async def lifespan(app: JobRunner): | ||
app.context.logger.info("Starting scheduler...") | ||
app.scheduler.start() | ||
yield | ||
app.context.logger.info("Stopping scheduler...") | ||
app.scheduler.shutdown() | ||
|
||
|
||
def init_app(name: str = "job_runner", test_config: Optional[dict] = None) -> JobRunner: | ||
app = JobRunner(name, test_config, lifespan=lifespan) | ||
app.context.logger.info(app.config) | ||
|
||
app.include_router(status_router) | ||
|
||
# schedule jobs defined in config | ||
app.scheduler.schedule_jobs(app.context) | ||
|
||
app.context.logger.info("app running...") | ||
return app |
Oops, something went wrong.