lostluck commented on code in PR #33705:
URL: https://github.com/apache/beam/pull/33705#discussion_r1924489110


##########
sdks/go/pkg/beam/runners/prism/internal/environments.go:
##########
@@ -83,6 +96,33 @@ func runEnvironment(ctx context.Context, j *jobservices.Job, 
env string, wk *wor
        }
 }
 
+func selectAnyOfEnv(ap *pipepb.AnyOfEnvironmentPayload) *pipepb.Environment {
+       // Prefer external, then process, then docker, unknown environments are 
0.
+       ranks := map[string]int{
+               urns.EnvDocker:   1,
+               urns.EnvProcess:  5,
+               urns.EnvExternal: 10,
+       }
+
+       envs := ap.GetEnvironments()
+
+       slices.SortStableFunc(envs, func(a, b *pipepb.Environment) int {
+               rankA := ranks[a.GetUrn()]
+               rankB := ranks[b.GetUrn()]
+
+               // Reverse the comparison so our favourite is at the front

Review Comment:
   The reversal was partly to have an easier selection for the most choice 
environment: just the one at 0.
   
   I did consider the golf weighting but I'm also making use of the default 
zero value for anything in the map. So i biased for the higher weight being 
priority, vs risk a weird priority inversion if someone puts in negative 
numbers.
   
   I could avoid the negatives with a uint instead...
   
   As for the idiomatic question: it would be less idiomatic to return the 
"normal" compare number, then reverse the list. Neither really save lines of 
code (vs documentation). There is the argument that then the code is self 
documenting, but we don't really care about the order, just that we picked the 
"favourite".
   
   Finally, we can always change it later.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to