@@ -1456,6 +1456,40 @@ async def run(self, attempt: int) -> str: # type:ignore[reportUnusedParameter]
14561456 return "v2.0"
14571457
14581458
1459+ @workflow .defn (
1460+ name = "ContinueAsNewWithRampingVersion" ,
1461+ versioning_behavior = VersioningBehavior .PINNED ,
1462+ )
1463+ class ContinueAsNewWithRampingVersionV1 :
1464+ def __init__ (self ) -> None :
1465+ self ._should_continue_as_new = False
1466+
1467+ @workflow .run
1468+ async def run (self , attempt : int ) -> str :
1469+ if attempt > 0 :
1470+ return "v1.0"
1471+
1472+ await workflow .wait_condition (lambda : self ._should_continue_as_new )
1473+ workflow .continue_as_new (
1474+ arg = attempt + 1 ,
1475+ initial_versioning_behavior = workflow .ContinueAsNewVersioningBehavior .USE_RAMPING_VERSION ,
1476+ )
1477+
1478+ @workflow .signal
1479+ def do_continue_as_new (self ) -> None :
1480+ self ._should_continue_as_new = True
1481+
1482+
1483+ @workflow .defn (
1484+ name = "ContinueAsNewWithRampingVersion" ,
1485+ versioning_behavior = VersioningBehavior .PINNED ,
1486+ )
1487+ class ContinueAsNewWithRampingVersionV2 :
1488+ @workflow .run
1489+ async def run (self , attempt : int ) -> str : # type:ignore[reportUnusedParameter]
1490+ return "v2.0"
1491+
1492+
14591493async def wait_for_workflow_running_on_version (
14601494 handle : WorkflowHandle [Any , Any ], expected_build_id : str
14611495) -> None :
@@ -1545,6 +1579,64 @@ async def test_continue_as_new_with_version_upgrade(
15451579 assert result == "v2.0"
15461580
15471581
1582+ async def test_continue_as_new_with_ramping_version (
1583+ client : Client , env : WorkflowEnvironment
1584+ ):
1585+ if env .supports_time_skipping :
1586+ pytest .skip ("Test Server doesn't support worker deployments" )
1587+
1588+ deployment_name = f"deployment-can-ramping-{ uuid .uuid4 ()} "
1589+ v1 = WorkerDeploymentVersion (deployment_name = deployment_name , build_id = "1.0" )
1590+ v2 = WorkerDeploymentVersion (deployment_name = deployment_name , build_id = "2.0" )
1591+
1592+ async with (
1593+ new_worker (
1594+ client ,
1595+ ContinueAsNewWithRampingVersionV1 ,
1596+ deployment_config = WorkerDeploymentConfig (
1597+ version = v1 ,
1598+ use_worker_versioning = True ,
1599+ ),
1600+ ) as w1 ,
1601+ new_worker (
1602+ client ,
1603+ ContinueAsNewWithRampingVersionV2 ,
1604+ deployment_config = WorkerDeploymentConfig (
1605+ version = v2 ,
1606+ use_worker_versioning = True ,
1607+ ),
1608+ task_queue = w1 .task_queue ,
1609+ ),
1610+ ):
1611+ describe_resp = await wait_until_worker_deployment_visible (client , v1 )
1612+
1613+ resp2 = await set_current_deployment_version (
1614+ client , describe_resp .conflict_token , v1
1615+ )
1616+ await wait_for_worker_deployment_routing_config_propagation (
1617+ client , deployment_name , v1 .build_id
1618+ )
1619+
1620+ handle = await client .start_workflow (
1621+ "ContinueAsNewWithRampingVersion" ,
1622+ 0 ,
1623+ id = f"test-can-ramping-version-{ uuid .uuid4 ()} " ,
1624+ task_queue = w1 .task_queue ,
1625+ )
1626+ await wait_for_workflow_running_on_version (handle , v1 .build_id )
1627+
1628+ await wait_until_worker_deployment_visible (client , v2 )
1629+ await set_ramping_version (client , resp2 .conflict_token , v2 , 0 )
1630+ await wait_for_worker_deployment_routing_config_propagation (
1631+ client , deployment_name , v1 .build_id , v2 .build_id
1632+ )
1633+
1634+ await handle .signal (ContinueAsNewWithRampingVersionV1 .do_continue_as_new )
1635+
1636+ result = await handle .result ()
1637+ assert result == "v2.0"
1638+
1639+
15481640def test_worker_config_matches_init_params ():
15491641 """WorkerConfig TypedDict keys must match Worker.__init__ kwargs."""
15501642 import inspect
0 commit comments