-
Notifications
You must be signed in to change notification settings - Fork 10
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 #267 from wguanicedew/dev
Dev
- Loading branch information
Showing
14 changed files
with
431 additions
and
72 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# http://www.apache.org/licenses/LICENSE-2.0OA | ||
# | ||
# Authors: | ||
# - Wen Guan, <[email protected]>, 2019 - 2023 | ||
# - Wen Guan, <[email protected]>, 2019 - 2024 | ||
|
||
import datetime | ||
import random | ||
|
@@ -157,13 +157,19 @@ def get_new_requests(self): | |
if time.time() < self.start_at + 3600: | ||
if BaseAgent.poll_new_min_request_id_times % 30 == 0: | ||
# get_new_requests is called every 10 seconds. 30 * 10 = 300 seconds, which is 5 minutes. | ||
min_request_id = BaseAgent.min_request_id - 1000 | ||
if BaseAgent.min_request_id: | ||
min_request_id = BaseAgent.min_request_id - 1000 | ||
else: | ||
min_request_id = None | ||
else: | ||
min_request_id = BaseAgent.min_request_id | ||
else: | ||
if BaseAgent.poll_new_min_request_id_times % 180 == 0: | ||
# get_new_requests is called every 10 seconds. 180 * 10 = 300 seconds, which is 30 minutes. | ||
min_request_id = BaseAgent.min_request_id - 1000 | ||
if BaseAgent.min_request_id: | ||
min_request_id = BaseAgent.min_request_id - 1000 | ||
else: | ||
min_request_id = None | ||
else: | ||
min_request_id = BaseAgent.min_request_id | ||
|
||
|
@@ -184,6 +190,7 @@ def get_new_requests(self): | |
BaseAgent.min_request_id_cache[req_id] = time.time() | ||
if BaseAgent.min_request_id is None or BaseAgent.min_request_id > req_id: | ||
BaseAgent.min_request_id = req_id | ||
self.logger.info("new min_request_id: %s" % BaseAgent.min_request_id) | ||
core_requests.set_min_request_id(BaseAgent.min_request_id) | ||
|
||
event = NewRequestEvent(publisher_id=self.id, request_id=req_id) | ||
|
@@ -213,13 +220,19 @@ def get_running_requests(self): | |
if time.time() < self.start_at + 3600: | ||
if BaseAgent.poll_running_min_request_id_times % 30 == 0: | ||
# get_new_requests is called every 10 seconds. 30 * 10 = 300 seconds, which is 5 minutes. | ||
min_request_id = BaseAgent.min_request_id - 1000 | ||
if BaseAgent.min_request_id: | ||
min_request_id = BaseAgent.min_request_id - 1000 | ||
else: | ||
min_request_id = None | ||
else: | ||
min_request_id = BaseAgent.min_request_id | ||
else: | ||
if BaseAgent.poll_running_min_request_id_times % 180 == 0: | ||
# get_new_requests is called every 10 seconds. 180 * 10 = 1800 seconds, which is 30 minutes. | ||
min_request_id = BaseAgent.min_request_id - 1000 | ||
if BaseAgent.min_request_id: | ||
min_request_id = BaseAgent.min_request_id - 1000 | ||
else: | ||
min_request_id = None | ||
else: | ||
min_request_id = BaseAgent.min_request_id | ||
|
||
|
@@ -245,6 +258,7 @@ def get_running_requests(self): | |
BaseAgent.min_request_id_cache[req_id] = time.time() | ||
if BaseAgent.min_request_id is None or BaseAgent.min_request_id > req_id: | ||
BaseAgent.min_request_id = req_id | ||
self.logger.info("new min_request_id: %s" % BaseAgent.min_request_id) | ||
core_requests.set_min_request_id(BaseAgent.min_request_id) | ||
|
||
event = UpdateRequestEvent(publisher_id=self.id, request_id=req_id) | ||
|
@@ -295,6 +309,7 @@ def get_operation_requests(self): | |
|
||
if BaseAgent.min_request_id is None or BaseAgent.min_request_id > request_id: | ||
BaseAgent.min_request_id = request_id | ||
self.logger.info("new min_request_id: %s" % BaseAgent.min_request_id) | ||
BaseAgent.min_request_id_cache[request_id] = time.time() | ||
core_requests.set_min_request_id(BaseAgent.min_request_id) | ||
|
||
|
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,58 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0OA | ||
# | ||
# Authors: | ||
# - Wen Guan, <[email protected]>, 2024 | ||
|
||
|
||
""" | ||
operations related to Meta info. | ||
""" | ||
|
||
from idds.common.constants import MetaStatus | ||
from idds.orm import meta as orm_meta | ||
from idds.orm.base.session import read_session, transactional_session | ||
|
||
|
||
@transactional_session | ||
def add_meta_item(name, status=MetaStatus.Active, description=None, meta_info=None, session=None): | ||
""" | ||
Add a meta item. | ||
:param name: The meta name. | ||
:param status: The meta status. | ||
:param description: The meta description. | ||
:param meta_info: The metadata. | ||
:param session: The database session. | ||
""" | ||
return orm_meta.add_meta_item(name=name, status=status, description=description, | ||
meta_info=meta_info, session=session) | ||
|
||
|
||
@read_session | ||
def get_meta_item(name, session=None): | ||
""" | ||
Retrieve meta item. | ||
:param name: The meta name. | ||
:param session: The database session. | ||
:returns metainfo: dictionary of meta info | ||
""" | ||
orm_meta.get_meta_item(name=name, session=session) | ||
|
||
|
||
@read_session | ||
def get_meta_items(session=None): | ||
""" | ||
Retrieve meta items. | ||
:param session: The database session. | ||
:returns metainfo: List of dictionaries | ||
""" | ||
orm_meta.get_meta_items(session=session) |
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
57 changes: 57 additions & 0 deletions
57
main/lib/idds/orm/base/alembic/versions/354f8e5a5879_add_meta_info_table.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,57 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0OA | ||
# | ||
# Authors: | ||
# - Wen Guan, <[email protected]>, 2023 | ||
|
||
"""add meta info table | ||
Revision ID: 354f8e5a5879 | ||
Revises: 1bc6e82e8514 | ||
Create Date: 2024-01-09 10:26:54.783489+00:00 | ||
""" | ||
|
||
import datetime | ||
|
||
from alembic import op | ||
from alembic import context | ||
import sqlalchemy as sa | ||
|
||
from idds.common.constants import MetaStatus | ||
from idds.orm.base.types import EnumWithValue | ||
from idds.orm.base.types import JSON | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '354f8e5a5879' | ||
down_revision = '1bc6e82e8514' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']: | ||
schema = context.get_context().version_table_schema if context.get_context().version_table_schema else '' | ||
op.create_table('meta_info', | ||
sa.Column('meta_id', sa.BigInteger(), sa.Sequence('METAINFO_ID_SEQ', schema=schema)), | ||
sa.Column('name', sa.String(50), nullable=False), | ||
sa.Column('status', EnumWithValue(MetaStatus), nullable=False), | ||
sa.Column("created_at", sa.DateTime, default=datetime.datetime.utcnow, nullable=False), | ||
sa.Column("updated_at", sa.DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow, nullable=False), | ||
sa.Column("description", sa.String(1000)), | ||
sa.Column('meta_info', JSON()), | ||
schema=schema) | ||
op.create_primary_key('METAINFO_PK', 'meta_info', ['meta_id'], schema=schema) | ||
op.create_unique_constraint('METAINFO_NAME_UQ', 'meta_info', ['name'], schema=schema) | ||
|
||
|
||
def downgrade() -> None: | ||
if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']: | ||
schema = context.get_context().version_table_schema if context.get_context().version_table_schema else '' | ||
op.drop_constraint('METAINFO_NAME_UQ', table_name='meta_info', schema=schema) | ||
op.drop_constraint('METAINFO_PK', table_name='meta_info', schema=schema) | ||
op.drop_table('meta_info', schema=schema) |
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
Oops, something went wrong.