@@ -64,14 +64,14 @@ def __init__(self, task_id, task_name: str, msg_id):
6464class FlareAgent :
6565 def __init__ (
6666 self ,
67- pipe : Pipe ,
67+ pipe : Optional [ Pipe ] = None ,
6868 read_interval = 0.1 ,
6969 heartbeat_interval = 5.0 ,
70- heartbeat_timeout = 30 .0 ,
70+ heartbeat_timeout = 60 .0 ,
7171 resend_interval = 2.0 ,
7272 max_resends = None ,
73- submit_result_timeout = 30 .0 ,
74- metric_pipe = None ,
73+ submit_result_timeout = 60 .0 ,
74+ metric_pipe : Optional [ Pipe ] = None ,
7575 task_channel_name : str = PipeChannelName .TASK ,
7676 metric_channel_name : str = PipeChannelName .METRIC ,
7777 close_pipe : bool = True ,
@@ -103,21 +103,27 @@ def __init__(
103103 Usually for ``FilePipe`` we set to False, for ``CellPipe`` we set to True.
104104 decomposer_module (str): the module name which contains the external decomposers.
105105 """
106+ if pipe is None and metric_pipe is None :
107+ raise RuntimeError (
108+ "Please configure at least one pipe. Both the task pipe and the metric pipe are set to None."
109+ )
106110 flare_decomposers .register ()
107111 common_decomposers .register ()
108112 if decomposer_module :
109113 register_ext_decomposers (decomposer_module )
110114
111115 self .logger = logging .getLogger (self .__class__ .__name__ )
112116 self .pipe = pipe
113- self .pipe_handler = PipeHandler (
114- pipe = self .pipe ,
115- read_interval = read_interval ,
116- heartbeat_interval = heartbeat_interval ,
117- heartbeat_timeout = heartbeat_timeout ,
118- resend_interval = resend_interval ,
119- max_resends = max_resends ,
120- )
117+ self .pipe_handler = None
118+ if self .pipe :
119+ self .pipe_handler = PipeHandler (
120+ pipe = self .pipe ,
121+ read_interval = read_interval ,
122+ heartbeat_interval = heartbeat_interval ,
123+ heartbeat_timeout = heartbeat_timeout ,
124+ resend_interval = resend_interval ,
125+ max_resends = max_resends ,
126+ )
121127 self .submit_result_timeout = submit_result_timeout
122128 self .task_channel_name = task_channel_name
123129 self .metric_channel_name = metric_channel_name
@@ -148,14 +154,17 @@ def start(self):
148154 Returns: None
149155
150156 """
151- self .pipe .open (self .task_channel_name )
152- self .pipe_handler .set_status_cb (self ._status_cb , pipe_handler = self .pipe_handler , channel = self .task_channel_name )
153- self .pipe_handler .start ()
157+ if self .pipe :
158+ self .pipe .open (self .task_channel_name )
159+ self .pipe_handler .set_status_cb (
160+ self ._status_cb , pipe_handler = self .pipe_handler , channel = self .task_channel_name
161+ )
162+ self .pipe_handler .start ()
154163
155164 if self .metric_pipe :
156165 self .metric_pipe .open (self .metric_channel_name )
157166 self .metric_pipe_handler .set_status_cb (
158- self ._status_cb , pipe_handler = self .metric_pipe_handler , channel = self .metric_channel_name
167+ self ._metrics_status_cb , pipe_handler = self .metric_pipe_handler , channel = self .metric_channel_name
159168 )
160169 self .metric_pipe_handler .start ()
161170
@@ -164,6 +173,11 @@ def _status_cb(self, msg: Message, pipe_handler: PipeHandler, channel):
164173 self .asked_to_stop = True
165174 pipe_handler .stop (self ._close_pipe )
166175
176+ def _metrics_status_cb (self , msg : Message , pipe_handler : PipeHandler , channel ):
177+ self .logger .info (f"{ channel } pipe status changed to { msg .topic } : { msg .data } " )
178+ self .asked_to_stop = True
179+ pipe_handler .stop (self ._close_metric_pipe )
180+
167181 def stop (self ):
168182 """Stop the agent.
169183
@@ -172,9 +186,9 @@ def stop(self):
172186 Returns: None
173187
174188 """
175- self .logger .info ("Calling flare agent stop" )
176189 self .asked_to_stop = True
177- self .pipe_handler .stop (self ._close_pipe )
190+ if self .pipe_handler :
191+ self .pipe_handler .stop (self ._close_pipe )
178192 if self .metric_pipe_handler :
179193 self .metric_pipe_handler .stop (self ._close_metric_pipe )
180194
@@ -226,6 +240,8 @@ def get_task(self, timeout: Optional[float] = None) -> Optional[Task]:
226240 has been submitted.
227241
228242 """
243+ if not self .pipe_handler :
244+ raise RuntimeError ("task pipe is not available" )
229245 start_time = time .time ()
230246 while True :
231247 if self .asked_to_stop :
@@ -278,6 +294,8 @@ def submit_result(self, result, rc=RC.OK) -> bool:
278294 made a single time regardless whether the submission is successful.
279295
280296 """
297+ if not self .pipe_handler :
298+ raise RuntimeError ("task pipe is not available" )
281299 with self .task_lock :
282300 current_task = self .current_task
283301 if not current_task :
0 commit comments