Add migration to fix issues with previous migrations (#1480)
Fixes #1479 - Update null crawlTimeouts in db from null to 0 - Update crawlerChannel in configmaps
This commit is contained in:
parent
ad19941318
commit
950844dc92
@ -16,7 +16,7 @@ from pymongo.errors import InvalidName
|
|||||||
from .migrations import BaseMigration
|
from .migrations import BaseMigration
|
||||||
|
|
||||||
|
|
||||||
CURR_DB_VERSION = "0024"
|
CURR_DB_VERSION = "0025"
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|||||||
@ -0,0 +1,49 @@
|
|||||||
|
"""
|
||||||
|
Migration 0025 -- fix workflow database and configmap issues.
|
||||||
|
"""
|
||||||
|
from btrixcloud.crawlmanager import CrawlManager
|
||||||
|
from btrixcloud.migrations import BaseMigration
|
||||||
|
from btrixcloud.models import CrawlConfig, UpdateCrawlConfig
|
||||||
|
|
||||||
|
|
||||||
|
MIGRATION_VERSION = "0025"
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(BaseMigration):
|
||||||
|
"""Migration class."""
|
||||||
|
|
||||||
|
def __init__(self, mdb, migration_version=MIGRATION_VERSION):
|
||||||
|
super().__init__(mdb, migration_version)
|
||||||
|
|
||||||
|
async def migrate_up(self):
|
||||||
|
"""Perform migration up.
|
||||||
|
|
||||||
|
Set crawlTimeout to 0 in any workflows where it is not set, and
|
||||||
|
update configmap for each workflow to include crawlerChannel.
|
||||||
|
"""
|
||||||
|
mdb_crawl_configs = self.mdb["crawl_configs"]
|
||||||
|
try:
|
||||||
|
await mdb_crawl_configs.update_many(
|
||||||
|
{"crawlTimeout": None},
|
||||||
|
{"$set": {"crawlTimeout": 0}},
|
||||||
|
)
|
||||||
|
# pylint: disable=broad-except
|
||||||
|
except Exception:
|
||||||
|
print(
|
||||||
|
"Error updating null crawlconfig crawlTimeouts to 0",
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
crawl_manager = CrawlManager()
|
||||||
|
async for config_dict in mdb_crawl_configs.find({}):
|
||||||
|
config = CrawlConfig.from_dict(config_dict)
|
||||||
|
try:
|
||||||
|
await crawl_manager.update_crawl_config(
|
||||||
|
config, UpdateCrawlConfig(crawlerChannel=config.crawlerChannel)
|
||||||
|
)
|
||||||
|
# pylint: disable=broad-except
|
||||||
|
except Exception as exc:
|
||||||
|
print(
|
||||||
|
f"Skipping configmap migration for config {config.id} due to error",
|
||||||
|
exc,
|
||||||
|
)
|
||||||
Loading…
Reference in New Issue
Block a user