2020
2121-record (state , {name :: binary () | {rabbit_types :vhost (), binary ()},
2222 type :: static | dynamic ,
23- config :: rabbit_shovel_behaviour :state ()}).
23+ config :: rabbit_shovel_behaviour :state (),
24+ last_reported_status :: rabbit_shovel_behaviour :status ()}).
2425
2526start_link (Type , Name , Config ) ->
2627 ShovelParameter = rabbit_shovel_util :get_shovel_parameter (Name ),
@@ -92,8 +93,8 @@ handle_cast(init_shovel, State = #state{config = Config}) ->
9293 Config2 = rabbit_shovel_behaviour :init_source (Config1 ),
9394 rabbit_log_shovel :debug (" Shovel ~ts has finished setting up its topology" , [human_readable_name (maps :get (name , Config2 ))]),
9495 State1 = State # state {config = Config2 },
95- ok = report_running (State1 ),
96- {noreply , State1 }.
96+ State2 = report_running (State1 ),
97+ {noreply , State2 }.
9798
9899
99100handle_info (Msg , State = # state {config = Config , name = Name }) ->
@@ -116,7 +117,9 @@ handle_info(Msg, State = #state{config = Config, name = Name}) ->
116117 rabbit_log_shovel :debug (" Shovel ~ts decided to stop due a message from destination: ~tp " , [human_readable_name (Name ), Reason ]),
117118 {stop , Reason , State };
118119 Config1 ->
119- {noreply , State # state {config = Config1 }}
120+ State1 = State # state {config = Config1 },
121+ State2 = maybe_report_running (State1 ),
122+ {noreply , State2 }
120123 end ;
121124 {stop , {inbound_conn_died , heartbeat_timeout }} ->
122125 rabbit_log_shovel :error (" Shovel ~ts detected missed heartbeats on source connection" , [human_readable_name (Name )]),
@@ -131,7 +134,9 @@ handle_info(Msg, State = #state{config = Config, name = Name}) ->
131134 rabbit_log_shovel :error (" Shovel ~ts decided to stop due a message from source: ~tp " , [human_readable_name (Name ), Reason ]),
132135 {stop , Reason , State };
133136 Config1 ->
134- {noreply , State # state {config = Config1 }}
137+ State1 = State # state {config = Config1 },
138+ State2 = maybe_report_running (State1 ),
139+ {noreply , State2 }
135140 end .
136141
137142terminate ({shutdown , autodelete }, State = # state {name = Name ,
@@ -209,20 +214,33 @@ human_readable_name(Name) ->
209214 ShovelName -> rabbit_misc :format (" '~ts '" , [ShovelName ])
210215 end .
211216
212- report_running (# state {config = Config } = State ) ->
217+ maybe_report_running (# state {config = Config ,
218+ last_reported_status = LastStatus } = State ) ->
219+ case rabbit_shovel_behaviour :status (Config ) of
220+ LastStatus ->
221+ State ;
222+ NewStatus ->
223+ report_status (NewStatus , State )
224+ end .
225+
226+ report_running (State ) ->
227+ report_status (running , State ).
228+
229+ report_status (Status , # state {config = Config } = State ) ->
213230 InUri = rabbit_shovel_behaviour :source_uri (Config ),
214231 OutUri = rabbit_shovel_behaviour :dest_uri (Config ),
215232 InProto = rabbit_shovel_behaviour :source_protocol (Config ),
216233 OutProto = rabbit_shovel_behaviour :dest_protocol (Config ),
217234 InEndpoint = rabbit_shovel_behaviour :source_endpoint (Config ),
218235 OutEndpoint = rabbit_shovel_behaviour :dest_endpoint (Config ),
219236 rabbit_shovel_status :report (State # state .name , State # state .type ,
220- {running , [{src_uri , rabbit_data_coercion :to_binary (InUri )},
237+ {Status , [{src_uri , rabbit_data_coercion :to_binary (InUri )},
221238 {src_protocol , rabbit_data_coercion :to_binary (InProto )},
222239 {dest_protocol , rabbit_data_coercion :to_binary (OutProto )},
223240 {dest_uri , rabbit_data_coercion :to_binary (OutUri )}]
224241 ++ props_to_binary (InEndpoint ) ++ props_to_binary (OutEndpoint )
225- }).
242+ }),
243+ State # state {last_reported_status = Status }.
226244
227245props_to_binary (Props ) ->
228246 [{K , rabbit_data_coercion :to_binary (V )} || {K , V } <- Props ].
0 commit comments