1414"""RSPY Staging processor."""
1515
1616import asyncio # for handling asynchronous tasks
17+ import json
1718import os
1819import time
1920import uuid
3738 load_external_auth_config_by_domain ,
3839)
3940from rs_server_common .s3_storage_handler .s3_storage_handler import S3StorageHandler
40- from rs_server_common .settings import env_bool
41+ from rs_server_common .settings import LOCAL_MODE
4142from rs_server_common .utils .logging import Logging
4243from starlette .datastructures import Headers
4344from starlette .requests import Request
4445
4546from .rspy_models import Feature , FeatureCollectionModel
4647
47- LOCAL_MODE = env_bool ("RSPY_LOCAL_MODE" , default = False )
48-
4948
5049# Custom authentication class
5150class TokenAuth (AuthBase ):
@@ -703,8 +702,10 @@ def dask_cluster_connect(self) -> Client: # pylint: disable=too-many-branches,t
703702 address = os .environ ["DASK_GATEWAY__ADDRESS" ],
704703 auth = gateway_auth ,
705704 )
706- clusters = gateway .list_clusters ()
707- self .logger .debug (f"The list of clusters: { clusters } " )
705+
706+ # Sort the clusters by newest first
707+ clusters = sorted (gateway .list_clusters (), key = lambda cluster : cluster .start_time , reverse = True )
708+ self .logger .debug (f"Cluster list for gateway { os .environ ['DASK_GATEWAY__ADDRESS' ]!r} :{ clusters } " )
708709
709710 # In local mode, get the first cluster from the gateway.
710711 cluster_id = None
@@ -725,11 +726,11 @@ def dask_cluster_connect(self) -> Client: # pylint: disable=too-many-branches,t
725726 )
726727
727728 if not cluster_id :
728- raise IndexError (f"No dask cluster named ' { cluster_name } ' was found." )
729+ raise IndexError (f"Dask cluster with 'cluster_name'= { cluster_name !r } was not found." )
729730
730731 self .cluster = gateway .connect (cluster_id )
731-
732732 self .logger .info (f"Successfully connected to the { cluster_name } dask cluster" )
733+
733734 except KeyError as e :
734735 self .logger .exception (
735736 "Failed to retrieve the required connection details for "
0 commit comments