Class | Nanite::State |
In: |
lib/nanite/state.rb
|
Parent: | Object |
this class encapsulates the state of a nanite system using redis as the data store. here is the schema, for each agent we store a number of items, for a nanite with the identity: nanite-foobar we store the following things:
nanite-foobar: 0.72 # load average or ‘status’ s-nanite-foobar: { /foo/bar, /foo/nik } # a SET of the provided services tg-nanite-foobar: { foo-42, customer-12 } # a SET of the tags for this agent t-nanite-foobar: 123456789 # unix timestamp of the last state update
also we do an inverted index for quick lookup of agents providing a certain service, so for each service the agent provides, we add the nanite to a SET of all the nanites that provide said service:
foo/bar: { nanite-foobar, nanite-nickelbag, nanite-another } # redis SET
we do that same thing for tags: some-tag: { nanite-foobar, nanite-nickelbag, nanite-another } # redis SET
This way we can do a lookup of what nanites provide a set of services and tags based on redis SET intersection:
nanites_for(’/gems/list’, ‘some-tag’)
of these two service tags