Skip to content

Commit

Permalink
Merge pull request #1104 from javierbrk/shared-state-async_intial_pub…
Browse files Browse the repository at this point in the history
…lish

Shared state async intial publish
  • Loading branch information
G10h4ck authored May 10, 2024
2 parents f326ad8 + 8c9a6fe commit 727af91
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 15 deletions.
21 changes: 21 additions & 0 deletions packages/shared-state-async/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,24 @@ https://openwrt.org/docs/guide-developer/gdb
VoCore2: Develop for OpenWrt on Qt Creator
https://vonger.cn/?p=14657

=== Plugin related notes
Plugins must be registered into shared-state-async by using the config file. UCI infrastructure is preferred

[source,console]
--------------------------------------------------------------------------------
mSc="plugin_name"
uci set shared-state.${mSc}=dataType
uci set shared-state.${mSc}.name='plugin-name'
uci set shared-state.${mSc}.scope='community'
uci set shared-state.${mSc}.ttl='1200'
uci set shared-state.${mSc}.update_interval='120'
uci commit shared-state
--------------------------------------------------------------------------------

Publishers must be located at +/usr/share/shared-state/publishers+
All Publishers will be called at least once using shared-state-async-publish-all

Sync is called automatically by shared-state-async according to "update_interval" parameter
"ttl" stands for "time to live" and will decrease until 0.
Data contents will be erased if "ttl" reaches 0.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ start_service()
procd_set_param stderr 1
procd_set_param term_timeout 10
procd_close_instance

#wait 10 secconds in detached mode and call publishres
((sleep 10; shared-state-async-publish-all)&)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

unique_append()
{
grep -qF "$1" "$2" || echo "$1" >> "$2"
}

unique_append \
'*/30 * * * * ((sleep $(($RANDOM % 120)); shared-state-async-publish-all &> /dev/null)&)' \
/etc/crontabs/root
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

for publisher in /usr/share/shared-state/publishers/* ; do
[ -x "$publisher" ] && "$publisher";
done

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ uci set shared-state.babel_links_info.ttl='2400'
uci set shared-state.babel_links_info.update_interval='30'
uci commit shared-state

unique_append \
'*/30 * * * * ((sleep $(($RANDOM % 120)); shared-state-publish_babel_links_info &> /dev/null)&)' \
/etc/crontabs/root
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Tests network_nodes #network_nodes', function()
end)

it('a simple test to get babel info and assert requiered fields are present', function()
package.path = package.path .. ";packages/shared-state-babel_links_info/files/usr/bin/?;;"
package.path = package.path .. ";packages/shared-state-babel_links_info/files/usr/share/shared-state/publishers/?;;"
require("shared-state-publish_babel_links_info")

babelinfo = get_babel_links_info()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
[ "x$ACTION" == "xifup" ] && ((sleep 30; shared-state-publish_bat_hosts; shared-state-async sync bat-hosts)&)
[ "x$ACTION" == "xifup" ] && ((sleep 30; /usr/share/shared-state/publishers/shared-state-publish_bat_hosts)&)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ uci set shared-state.bat_hosts.ttl='2400'
uci set shared-state.bat_hosts.update_interval='30'
uci commit shared-state

unique_append \
'*/30 * * * * ((sleep $(($RANDOM % 120)); shared-state-publish_bat_hosts &> /dev/null)&)' \
/etc/crontabs/root
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
[ "x$ACTION" == "xifup" ] && ((sleep 30; /usr/share/shared-state/publishers/shared-state-publish_bat_links)&)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ uci set shared-state.bat_links_info.scope='community'
uci set shared-state.bat_links_info.ttl='2400'
uci set shared-state.bat_links_info.update_interval='30'
uci commit shared-state

unique_append \
'*/30 * * * * ((sleep $(($RANDOM % 120)); shared-state-publish_bat_links_info &> /dev/null)&)' \
/etc/crontabs/root
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe('Tests bat_links_info #bat_links_info', function ()
return iwinfo.mocks.wlan1_mesh_mac
end)

package.path = package.path .. ";packages/shared-state-bat_links_info/files/usr/bin/?;;"
package.path = package.path .. ";packages/shared-state-bat_links_info/files/usr/share/shared-state/publishers/?;;"
require ("shared-state-publish_bat_links_info")

it('a simple test to get node info and assert requiered fields are present', function()
Expand Down

0 comments on commit 727af91

Please sign in to comment.