Browse Source

new: [compose-core] provide ``get_service_incoming_relations`` to list services linked to a service

cache-relation
Valentin Lab 9 months ago
parent
commit
8c0d97facb
  1. 31
      bin/compose-core

31
bin/compose-core

@ -2209,6 +2209,37 @@ get_service_relation() {
export -f get_service_relation
## From a service and a relation, get all relations targeting given
## service with given relation.
##
## Returns a NUL separated list of couple of:
## (base_service, relation_config)
##
get_service_incoming_relations() {
local service="$1" relation="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$ALL_RELATIONS")" \
s rn ts rc td
if [ -e "$cache_file" ]; then
#debug "$FUNCNAME: SESSION cache hit $1"
cat "$cache_file"
return 0
fi
if [ -z "$ALL_RELATIONS" ]; then
err "Can't access global \$ALL_RELATIONS"
return 1
fi
while read-0 s rn ts rc _td; do
[[ "$ts" == "$service" ]] || continue
[[ "$rn" == "$relation" ]] || continue
relation_data_file=$(get_relation_data_file "$s" "$ts" "$rn" "$rc") || return 1
printf "%s\0" "$s" "$(cat "$relation_data_file")"
done < <(cat "$ALL_RELATIONS") > "$cache_file"
cat "$cache_file"
}
export -f get_service_incoming_relations
export TRAVERSE_SEPARATOR=:
## Traverse on first service satisfying relation
service:traverse() {

Loading…
Cancel
Save