mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-11-06 07:09:21 +08:00
Avoid to handle a late init message
Signed-off-by: Chenxiong Qi <cqi@redhat.com>
This commit is contained in:
@@ -153,6 +153,16 @@ def init(msg_id, module_build_id, module_build_state):
|
||||
"""
|
||||
build = models.ModuleBuild.get_by_id(db_session, module_build_id)
|
||||
|
||||
state_init = models.BUILD_STATES["init"]
|
||||
if module_build_state == state_init and build.state != state_init:
|
||||
log.warning(
|
||||
"Module build %r has moved to %s state already.",
|
||||
build, models.INVERSE_BUILD_STATES[build.state])
|
||||
log.warning(
|
||||
"Ignore this message %s. Is there something wrong with the frontend"
|
||||
" that sends duplicate messages?", msg_id)
|
||||
return
|
||||
|
||||
# for MockModuleBuilder, set build logs dir to mock results dir
|
||||
# before build_logs start
|
||||
if conf.system == "mock":
|
||||
|
||||
@@ -6,7 +6,7 @@ import os
|
||||
from mock import patch, PropertyMock
|
||||
|
||||
from module_build_service import build_logs, conf
|
||||
from module_build_service.common.models import ModuleBuild
|
||||
from module_build_service.common.models import BUILD_STATES, ModuleBuild
|
||||
from module_build_service.common.utils import load_mmd, mmd_to_str
|
||||
from module_build_service.scheduler.db_session import db_session
|
||||
import module_build_service.scheduler.handlers.modules
|
||||
@@ -180,3 +180,13 @@ class TestModuleInit:
|
||||
# Make sure the module entered the failed state
|
||||
assert build.state == 4, build.state
|
||||
assert "Failed to get the latest commit for" in build.state_reason
|
||||
|
||||
def test_do_not_handle_a_duplicate_late_init_message(self):
|
||||
build = db_session.query(ModuleBuild).filter(
|
||||
ModuleBuild.name == "testmodule").one()
|
||||
build.state = BUILD_STATES["wait"]
|
||||
db_session.commit()
|
||||
|
||||
with patch.object(module_build_service.scheduler.handlers.modules, "log") as log:
|
||||
self.fn("msg-id-123", build.id, BUILD_STATES["init"])
|
||||
assert 2 == log.warning.call_count
|
||||
|
||||
Reference in New Issue
Block a user