@@ -228,13 +228,9 @@ defmodule Cog.Command.Pipeline.Executor do
228228 # fail_pipeline_with_error({:disabled_bundle, bundle}, state)
229229 #
230230 case assign_relay ( relays , bundle_name , version ) do
231- { nil , _ } ->
232- fail_pipeline_with_error ( { :no_relays , bundle_name } , state )
233- { :no_relay_group , _ } ->
234- fail_pipeline_with_error ( { :no_relay_group , bundle_name } , state )
235- { :no_enabled_relays , _ } ->
236- fail_pipeline_with_error ( { :no_enabled_relays , bundle_name } , state )
237- { relay , relays } ->
231+ { :error , reason } ->
232+ fail_pipeline_with_error ( { reason , bundle_name } , state )
233+ { :ok , { relay , relays } } ->
238234 topic = "/bot/commands/#{ relay } /#{ bundle_name } /#{ command_name } "
239235 reply_to_topic = "#{ state . topic } /reply"
240236 req = request_for_plan ( current_plan , request , user , reply_to_topic , state . service_token )
@@ -671,35 +667,31 @@ defmodule Cog.Command.Pipeline.Executor do
671667 end
672668
673669 defp assign_relay ( relays , bundle_name , bundle_version ) do
674- # If the bundle is assigned to a relay group carry on, otherwise bail
675- if Cog.Repository.Bundles . assigned_to_group? ( bundle_name ) do
676- case Map . get ( relays , bundle_name ) do
677- # No assignment so let's pick one
678- nil ->
679- case Relays . pick_one ( bundle_name , bundle_version ) do
680- # No relays available
681- { :error , :no_relays } ->
682- { nil , relays }
683- # relays exist, but are disabled
684- { :error , :no_enabled_relays } ->
685- { :no_enabled_relays , relays }
686- # Store the selected relay in the relay cache
687- { :ok , relay } ->
688- { relay , Map . put ( relays , bundle_name , relay ) }
689- end
690- # Relay was previously assigned
691- relay ->
692- # Is the bundle still available on the relay? If not, remove the current assignment from the cache
693- # and select a new relay
694- if Relays . relay_available? ( relay , bundle_name , bundle_version ) do
695- { relay , relays }
696- else
697- relays = Map . delete ( relays , bundle_name )
698- assign_relay ( relays , bundle_name , bundle_version )
699- end
700- end
701- else
702- { :no_relay_group , relays }
670+ case Map . get ( relays , bundle_name ) do
671+ # No assignment so let's pick one
672+ nil ->
673+ case Relays . pick_one ( bundle_name , bundle_version ) do
674+ # Store the selected relay in the relay cache
675+ { :ok , relay } ->
676+ { :ok , { relay , Map . put ( relays , bundle_name , relay ) } }
677+ error ->
678+ # Query DB to clarify error before reporting to the user
679+ if Cog.Repository.Bundles . assigned_to_group? ( bundle_name ) do
680+ error
681+ else
682+ { :error , :no_relay_group }
683+ end
684+ end
685+ # Relay was previously assigned
686+ relay ->
687+ # Is the bundle still available on the relay? If not, remove the current assignment from the cache
688+ # and select a new relay
689+ if Relays . relay_available? ( relay , bundle_name , bundle_version ) do
690+ { :ok , { relay , relays } }
691+ else
692+ relays = Map . delete ( relays , bundle_name )
693+ assign_relay ( relays , bundle_name , bundle_version )
694+ end
703695 end
704696 end
705697
0 commit comments