|
12 | 12 | """
|
13 | 13 |
|
14 | 14 | import asyncio
|
| 15 | +import contextlib |
15 | 16 | import datetime
|
16 | 17 | import functools
|
17 | 18 | import logging
|
|
34 | 35 | from servicelib.common_headers import UNDEFINED_DEFAULT_SIMCORE_USER_AGENT_VALUE
|
35 | 36 | from servicelib.logging_utils import log_context
|
36 | 37 | from servicelib.rabbitmq import RabbitMQClient, RabbitMQRPCClient
|
37 |
| -from servicelib.redis import RedisClientSDK |
| 38 | +from servicelib.redis import CouldNotAcquireLockError, RedisClientSDK |
38 | 39 | from servicelib.redis_utils import exclusive
|
39 | 40 |
|
40 | 41 | from ...constants import UNDEFINED_STR_METADATA
|
@@ -281,16 +282,29 @@ def _start_scheduling(
|
281 | 282 | project_id: ProjectID,
|
282 | 283 | iteration: Iteration,
|
283 | 284 | ) -> None:
|
284 |
| - # create a new schedule task |
285 |
| - p = functools.partial( |
286 |
| - self._schedule_pipeline, |
287 |
| - user_id=user_id, |
288 |
| - project_id=project_id, |
289 |
| - iteration=iteration, |
290 |
| - pipeline_params=pipeline_params, |
291 |
| - ) |
| 285 | + async def _exclusive_safe_schedule_pipeline( |
| 286 | + *, |
| 287 | + user_id: UserID, |
| 288 | + project_id: ProjectID, |
| 289 | + iteration: Iteration, |
| 290 | + pipeline_params: ScheduledPipelineParams, |
| 291 | + ) -> None: |
| 292 | + with contextlib.suppress(CouldNotAcquireLockError): |
| 293 | + await self._schedule_pipeline( |
| 294 | + user_id=user_id, |
| 295 | + project_id=project_id, |
| 296 | + iteration=iteration, |
| 297 | + pipeline_params=pipeline_params, |
| 298 | + ) |
| 299 | + |
292 | 300 | pipeline_params.scheduler_task = start_periodic_task(
|
293 |
| - p, |
| 301 | + functools.partial( |
| 302 | + _exclusive_safe_schedule_pipeline, |
| 303 | + user_id=user_id, |
| 304 | + project_id=project_id, |
| 305 | + iteration=iteration, |
| 306 | + pipeline_params=pipeline_params, |
| 307 | + ), |
294 | 308 | interval=_SCHEDULER_INTERVAL,
|
295 | 309 | task_name=_TASK_NAME_TEMPLATE.format(
|
296 | 310 | user_id=user_id, project_id=project_id, iteration=iteration
|
|
0 commit comments