@@ -1474,12 +1474,8 @@ where
14741474 return Err ( refuse ( StatusCode :: CONFLICT , "task_queue_mismatch" ) ) ;
14751475 }
14761476 let request = self . workflow_poll_request ( worker_id, queue, id, default_wait, & [ "workflow" ] ) . await ?;
1477- if let Some ( mut replay) = self . replay_workflow_poll ( & request, worker_id, queue) . await ? {
1478- if replay[ "task" ] . is_object ( ) {
1479- super :: history_pages:: compress ( & mut replay[ "task" ] , encoding) ?;
1480- }
1481- replay[ "server_capabilities" ] = capabilities ( ) ;
1482- return Ok ( replay) ;
1477+ if let Some ( replay) = self . replay_workflow_poll ( & request, worker_id, queue) . await ? {
1478+ return replayed_poll ( replay, encoding) ;
14831479 }
14841480 Some ( request)
14851481 }
@@ -1531,29 +1527,41 @@ where
15311527 ) ;
15321528 }
15331529 if tokio:: time:: Instant :: now ( ) >= deadline {
1534- if let Some ( request) = & poll_request {
1535- self . remember_empty_workflow_poll ( request, "empty" ) . await ?;
1536- }
1537- return Ok (
1538- json ! ( { "task" : null, "poll_status" : "empty" , "server_capabilities" : capabilities( ) } ) ,
1539- ) ;
1530+ return self . no_task_answer ( & body, poll_request. as_ref ( ) , "empty" , encoding) . await ;
15401531 }
15411532 if self
15421533 . poll_queue_changed ( & body, kind, & mut cross_kind)
15431534 . await ?
15441535 && tokio:: time:: Instant :: now ( ) < deadline
15451536 {
1546- if let Some ( request) = & poll_request {
1547- self . remember_empty_workflow_poll ( request, "task_queue_changed" ) . await ?;
1548- }
1549- return Ok (
1550- json ! ( { "task" : null, "poll_status" : "task_queue_changed" , "server_capabilities" : capabilities( ) } ) ,
1551- ) ;
1537+ return self . no_task_answer ( & body, poll_request. as_ref ( ) , "task_queue_changed" , encoding) . await ;
1538+ }
1539+ #[ cfg( debug_assertions) ]
1540+ if let Some ( request) = & poll_request {
1541+ super :: poll_pauses:: stop_at ( & request. id , super :: poll_pauses:: PollPoint :: Waiting ) . await ;
15521542 }
15531543 pace. wait ( wake, deadline) . await ;
15541544 }
15551545 }
15561546
1547+ /// A poll's answer when it leased nothing. Under a request ID, a
1548+ /// duplicate's lease committed after this poll's last probe replays
1549+ /// instead, as a retry with that ID would see it.
1550+ async fn no_task_answer (
1551+ & self ,
1552+ body : & Value ,
1553+ poll_request : Option < & super :: workflow_poll_requests:: WorkflowPollRequest > ,
1554+ poll_status : & str ,
1555+ encoding : Option < & ' static str > ,
1556+ ) -> Result < Value > {
1557+ if let Some ( request) = poll_request
1558+ && let Some ( lease) = self . remember_empty_workflow_poll ( request, text ( body, "worker_id" ) ?, text ( body, "task_queue" ) ?, poll_status) . await ?
1559+ {
1560+ return replayed_poll ( lease, encoding) ;
1561+ }
1562+ Ok ( json ! ( { "task" : null, "poll_status" : poll_status, "server_capabilities" : capabilities( ) } ) )
1563+ }
1564+
15571565 /// Whether a held workflow or activity poll should claim again.
15581566 async fn task_poll_ready (
15591567 & self ,
@@ -1659,8 +1667,7 @@ where
16591667 // replays a validation answer itself before claiming.
16601668 if let Some ( request) = poll_request {
16611669 Self :: bind_workflow_poll ( tx, request) . await ?;
1662- if let Some ( answer) = self . deliverable_workflow_poll ( tx, request, worker_id, queue) . await ?
1663- && answer[ "task" ] . is_object ( )
1670+ if let Some ( answer) = self . deliverable_workflow_lease ( tx, request, worker_id, queue) . await ?
16641671 && answer[ "task" ] [ "task_kind" ] != "update_validation"
16651672 {
16661673 return Ok ( Some ( answer[ "task" ] . clone ( ) ) ) ;
@@ -4176,6 +4183,16 @@ pub(super) fn reject_fields(body: &Value, allowed: &[&str]) -> Result<()> {
41764183 Ok ( ( ) )
41774184}
41784185
4186+ /// A replayed answer as a workflow poll delivers it: a lease takes this
4187+ /// request's history encoding.
4188+ pub ( super ) fn replayed_poll ( mut replay : Value , encoding : Option < & ' static str > ) -> Result < Value > {
4189+ if replay[ "task" ] . is_object ( ) {
4190+ super :: history_pages:: compress ( & mut replay[ "task" ] , encoding) ?;
4191+ }
4192+ replay[ "server_capabilities" ] = capabilities ( ) ;
4193+ Ok ( replay)
4194+ }
4195+
41794196pub ( crate ) fn capabilities ( ) -> Value {
41804197 let mut value = json ! ( { "supported_workflow_task_commands" : [ "schedule_activity" , "start_timer" , "start_child_workflow" , "open_condition_wait" , "open_signal_wait" , "record_version_marker" , "record_side_effect" , "complete_workflow" , "fail_workflow" , "continue_as_new" , "complete_update" , "fail_update" ] ,
41814198 "worker_deregistration_fencing" : { "schema" : "durable-workflow.v2.worker-deregistration.v1" , "supported" : true , "receipt_retention_seconds" : 600 , "endpoint" : "/worker/registrations/{workerId}/deregister" } ,
0 commit comments