<spanid="evennia-scripts-monitorhandler"></span><h1>evennia.scripts.monitorhandler<aclass="headerlink"href="#module-evennia.scripts.monitorhandler"title="Link to this heading">¶</a></h1>
<p>Monitors - catch changes to model fields and Attributes.</p>
<p>The MONITOR_HANDLER singleton from this module offers the following
functionality:</p>
<ulclass="simple">
<li><dlclass="simple">
<dt>Field-monitor - track a object’s specific database field and perform</dt><dd><p>an action whenever that field <em>changes</em> for whatever reason.</p>
</dd>
</dl>
</li>
<li><dlclass="simple">
<dt>Attribute-monitor tracks an object’s specific Attribute and perform</dt><dd><p>an action whenever that Attribute <em>changes</em> for whatever reason.</p>
<emclass="property"><spanclass="k"><spanclass="pre">class</span></span><spanclass="w"></span></em><spanclass="sig-prename descclassname"><spanclass="pre">evennia.scripts.monitorhandler.</span></span><spanclass="sig-name descname"><spanclass="pre">MonitorHandler</span></span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler"title="Link to this definition">¶</a></dt>
<spanclass="sig-name descname"><spanclass="pre">__init__</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.__init__"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.__init__"title="Link to this definition">¶</a></dt>
<spanclass="sig-name descname"><spanclass="pre">save</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.save"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.save"title="Link to this definition">¶</a></dt>
<dd><p>Store our monitors to the database. This is called
by the server process.</p>
<p>Since dbserialize can’t handle defaultdicts, we convert to an
intermediary save format ((obj,fieldname, idstring, callback, kwargs), …)</p>
<spanclass="sig-name descname"><spanclass="pre">restore</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">server_reload</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">True</span></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.restore"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.restore"title="Link to this definition">¶</a></dt>
<dd><p>Restore our monitors after a reload. This is called
<spanclass="sig-name descname"><spanclass="pre">at_update</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">obj</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">fieldname</span></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.at_update"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.at_update"title="Link to this definition">¶</a></dt>
<dd><p>Called by the field/attribute as it saves.</p>
<li><p><strong>obj</strong> (<em>Typeclassed Entity</em>) – The entity on which to monitor a
field or Attribute.</p></li>
<li><p><strong>fieldname</strong> (<em>str</em>) – Name of field (db_*) or Attribute to monitor.</p></li>
<li><p><strong>callback</strong> (<em>callable</em>) – A callable on the form <ahref="#id1"><spanclass="problematic"id="id2">**</span></a>callable(<ahref="#id3"><spanclass="problematic"id="id4">**</span></a>kwargs),
where kwargs holds keys fieldname and obj.</p></li>
<li><p><strong>idstring</strong> (<em>str</em><em>, </em><em>optional</em>) – An id to separate this monitor from other monitors
of the same field and object.</p></li>
<li><p><strong>persistent</strong> (<em>bool</em><em>, </em><em>optional</em>) – If False, the monitor will survive
a server reload but not a cold restart. This is default.</p></li>
<li><p><strong>category</strong> (<em>str</em><em>, </em><em>optional</em>) – This is only used if <strong>fieldname</strong> refers to
an Attribute (i.e. it does not start with <strong>db_</strong>). You must specify this
if you want to target an Attribute with a category.</p></li>
<li><p><strong>session</strong> (<aclass="reference internal"href="evennia.server.session.html#evennia.server.session.Session"title="evennia.server.session.Session"><em>Session</em></a>) – If this keyword is given, the monitorhandler will
correctly analyze it and remove the monitor if after a reload/reboot
the session is no longer valid.</p></li>
<li><p><strong>any</strong> (<em>any</em>) – Any other kwargs are passed on to the callback. Remember that
<spanclass="sig-name descname"><spanclass="pre">remove</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">obj</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">fieldname</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">idstring</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">''</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">category</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.remove"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.remove"title="Link to this definition">¶</a></dt>
<spanclass="sig-name descname"><spanclass="pre">clear</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.clear"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.clear"title="Link to this definition">¶</a></dt>
<spanclass="sig-name descname"><spanclass="pre">all</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">obj</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.all"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.all"title="Link to this definition">¶</a></dt>
<dd><p>List all monitors or all monitors of a given object.</p>