forked from y-scope/clp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Put search scheduler db creation into its own script
- Old scheduling tables remain untouched and will only be removed after search/compression scheduler changes are in
- Loading branch information
1 parent
7af5925
commit ba65660
Showing
3 changed files
with
62 additions
and
22 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
55 changes: 55 additions & 0 deletions
55
components/clp-py-utils/clp_py_utils/initialize-search-scheduler-db.py
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,55 @@ | ||
#!/usr/bin/env python3 | ||
import argparse | ||
import logging | ||
import sys | ||
from contextlib import closing | ||
|
||
from clp_py_utils.clp_config import Database, SEARCH_JOBS_TABLE_NAME | ||
from clp_py_utils.core import read_yaml_config_file | ||
from job_orchestration.search_scheduler.common import JobStatus | ||
from sql_adapter import SQL_Adapter | ||
|
||
# Setup logging | ||
# Create logger | ||
logger = logging.getLogger(__file__) | ||
logger.setLevel(logging.INFO) | ||
# Setup console logging | ||
logging_console_handler = logging.StreamHandler() | ||
logging_formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s") | ||
logging_console_handler.setFormatter(logging_formatter) | ||
logger.addHandler(logging_console_handler) | ||
|
||
|
||
def main(argv): | ||
args_parser = argparse.ArgumentParser(description="Sets up metadata tables for job orchestration.") | ||
args_parser.add_argument('--config', required=True, help="Database config file.") | ||
parsed_args = args_parser.parse_args(argv[1:]) | ||
|
||
try: | ||
database_config = Database.parse_obj(read_yaml_config_file(parsed_args.config)) | ||
if database_config is None: | ||
raise ValueError(f"Database configuration file '{parsed_args.config}' is empty.") | ||
sql_adapter = SQL_Adapter(database_config) | ||
with closing(sql_adapter.create_connection(True)) as scheduling_db, \ | ||
closing(scheduling_db.cursor(dictionary=True)) as scheduling_db_cursor: | ||
scheduling_db_cursor.execute(f""" | ||
CREATE TABLE IF NOT EXISTS `{SEARCH_JOBS_TABLE_NAME}` ( | ||
`id` INT NOT NULL AUTO_INCREMENT, | ||
`status` INT NOT NULL DEFAULT '{JobStatus.PENDING}', | ||
`submission_time` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
`search_config` VARBINARY(60000) NOT NULL, | ||
PRIMARY KEY (`id`) USING BTREE, | ||
INDEX `JOB_STATUS` (`status`) USING BTREE | ||
) ROW_FORMAT=DYNAMIC | ||
""") | ||
|
||
scheduling_db.commit() | ||
except: | ||
logger.exception("Failed to create search scheduler tables.") | ||
return -1 | ||
|
||
return 0 | ||
|
||
|
||
if '__main__' == __name__: | ||
sys.exit(main(sys.argv)) |
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