Skip to content

Commit aa55cdc

Browse files
committed
Massive documentation overhaul
1 parent 0f6c804 commit aa55cdc

File tree

3 files changed

+121
-63
lines changed

3 files changed

+121
-63
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Adds two new, simple-to-use objects:
66
- SignalResponder (for receiving state signals, locking onto publishers, and publishing responses)
77

88
Also provides two dataclass specifications:
9-
- Signal (state signal protocol definition)
10-
- Response (response protocol definition)
9+
- Signal (state signal protocol payload definition)
10+
- Response (response protocol payload definition)
1111

1212
Combining redis pubsub features with state signal + response protocols,
1313
these additions make state signal publishing, subscribing, receiving,
@@ -19,3 +19,17 @@ See full documentation [here](https://distributed-system-analysis.github.io/stat
1919
The state-signals PyPI package is available [here](https://pypi.org/project/state-signals)
2020

2121
To install, run `pip install state-signals`
22+
23+
# REQUIREMENTS
24+
The use of this module requires the existence of an accessible redis server.
25+
- Redis can easily be installed with a `yum install redis` (or replace yum with package manager of choice).
26+
27+
A redis server can be started with the `redis-server` command.
28+
- The default port is 6379 (also default for state-signals), but can be changed with `--port (port)`
29+
- A config file can also be used for greater control/detail `redis-server \path\to\config`
30+
- Example/default config available (here)[https://download.redis.io/redis-stable/redis.conf]
31+
32+
See https://redis.io/ for more details and usage
33+
34+
# PROTOCOL / BEHAVIORS
35+

docs/index.html

Lines changed: 77 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
66
<meta name="generator" content="pdoc 0.10.0" />
77
<title>state_signals API documentation</title>
8-
<meta name="description" content="" />
8+
<meta name="description" content="State/Event Signal Module …" />
99
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
1010
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
1111
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
@@ -22,38 +22,60 @@
2222
<h1 class="title">Module <code>state_signals</code></h1>
2323
</header>
2424
<section id="section-intro">
25+
<p>State/Event Signal Module</p>
26+
<p>Adds two new, simple-to-use objects:</p>
27+
<ul>
28+
<li>SignalExporter
29+
(for publishing state signals and handling subscribers + responses)
30+
</li>
31+
<li>SignalResponder
32+
(for receiving state signals, locking onto publishers, and publishing responses)</li>
33+
</ul>
34+
<p>Also provides two dataclass specifications:</p>
35+
<ul>
36+
<li>Signal
37+
(state signal protocol payload definition)
38+
</li>
39+
<li>Response
40+
(response protocol payload definition)</li>
41+
</ul>
42+
<p>Combining redis pubsub features with state signal + response protocols,
43+
these additions make state signal publishing, subscribing, receiving,
44+
and responding incredibly easy to integrate into any code.</p>
2545
<details class="source">
2646
<summary>
2747
<span>Expand source code</span>
2848
</summary>
29-
<pre><code class="python">from dataclasses import dataclass
30-
from enum import Enum
31-
from typing import Any, Dict, Iterator, List, Optional, Tuple
32-
import redis
33-
import platform
34-
import json
35-
import time
36-
import uuid
37-
import logging
38-
39-
40-
&#34;&#34;&#34;
49+
<pre><code class="python">&#34;&#34;&#34;
4150
State/Event Signal Module
4251

4352
Adds two new, simple-to-use objects:
44-
- SignalExporter (for publishing state signals and handling subscribers + responses)
45-
- SignalResponder (for receiving state signals, locking onto publishers, and publishing responses)
53+
54+
- SignalExporter (for publishing state signals and handling subscribers + responses)
55+
- SignalResponder (for receiving state signals, locking onto publishers, and publishing responses)
4656

4757
Also provides two dataclass specifications:
48-
- Signal (state signal protocol payload definition)
49-
- Response (response protocol payload definition)
58+
59+
- Signal (state signal protocol payload definition)
60+
- Response (response protocol payload definition)
5061

5162
Combining redis pubsub features with state signal + response protocols,
5263
these additions make state signal publishing, subscribing, receiving,
5364
and responding incredibly easy to integrate into any code.
5465
&#34;&#34;&#34;
5566

5667

68+
from dataclasses import dataclass
69+
from enum import Enum
70+
from typing import Any, Dict, Iterator, List, Optional, Tuple
71+
import redis
72+
import platform
73+
import json
74+
import time
75+
import uuid
76+
import logging
77+
78+
5779
def _create_logger(
5880
class_name: str, process_name: str, log_level: str
5981
) -&gt; logging.Logger:
@@ -77,6 +99,10 @@ <h1 class="title">Module <code>state_signals</code></h1>
7799

78100

79101
class ResultCodes(Enum):
102+
&#34;&#34;&#34;
103+
All potential result codes when publishing a signal. See the publish_signal
104+
method under SignalExporter for more details.
105+
&#34;&#34;&#34;
80106
ALL_SUBS_SUCCESS = 0
81107
SUB_FAILED = 1
82108
MISSING_RESPONSE = 2
@@ -198,7 +224,7 @@ <h1 class="title">Module <code>state_signals</code></h1>
198224
log_level: str = &#34;INFO&#34;,
199225
) -&gt; None:
200226
&#34;&#34;&#34;
201-
Sets exporter object fields and generates unique publisher_id.
227+
init: Sets exporter object fields and generates unique publisher_id.
202228
Allows for specification of redis host/port. Also allows runner
203229
hostname to be inputted manually (otherwise will default to
204230
platform.node() value)
@@ -334,10 +360,11 @@ <h1 class="title">Module <code>state_signals</code></h1>
334360
is reached (default = 20s). Returns one of the below result codes based on
335361
signal publish/response success.
336362

337-
RESULT CODES:
338-
ALL_SUBS_SUCCESS = 0 = ALL SUBS RESPONDED WELL
339-
SUB_FAILED = 1 = ONE OR MORE SUB RESPONDED BADLY
340-
MISSING_RESPONE = 2 = NOT ALL SUBS RESPONDED
363+
Result Codes:
364+
365+
- ALL_SUBS_SUCCESS = 0 = all subs responded well
366+
- SUB_FAILED = 1 = one or more sub responded badly
367+
- MISSING_RESPONE = 2 = not all subs responded
341368
&#34;&#34;&#34;
342369
if not isinstance(timeout, int):
343370
raise TypeError(&#34;&#39;timeout&#39; arg must be an int value&#34;)
@@ -437,7 +464,7 @@ <h1 class="title">Module <code>state_signals</code></h1>
437464
log_level=&#34;INFO&#34;,
438465
) -&gt; None:
439466
&#34;&#34;&#34;
440-
Sets exporter object fields and generates unique responder_id.
467+
init: Sets responder object fields and generates unique responder_id.
441468
Allows for specification of redis host/port.
442469
&#34;&#34;&#34;
443470
self.logger = _create_logger(&#34;SignalResponder&#34;, responder_name, log_level)
@@ -667,12 +694,17 @@ <h3>Methods</h3>
667694
<span>(</span><span>value, names=None, *, module=None, qualname=None, type=None, start=1)</span>
668695
</code></dt>
669696
<dd>
670-
<div class="desc"><p>An enumeration.</p></div>
697+
<div class="desc"><p>All potential result codes when publishing a signal. See the publish_signal
698+
method under SignalExporter for more details.</p></div>
671699
<details class="source">
672700
<summary>
673701
<span>Expand source code</span>
674702
</summary>
675703
<pre><code class="python">class ResultCodes(Enum):
704+
&#34;&#34;&#34;
705+
All potential result codes when publishing a signal. See the publish_signal
706+
method under SignalExporter for more details.
707+
&#34;&#34;&#34;
676708
ALL_SUBS_SUCCESS = 0
677709
SUB_FAILED = 1
678710
MISSING_RESPONSE = 2</code></pre>
@@ -840,7 +872,7 @@ <h3>Methods</h3>
840872
Also handles subscriber recording and response reading/awaiting. Uses the standard
841873
signal protocol for all published messages. Easy-to-use interface for publishing
842874
legal signals and handling responders.</p>
843-
<p>Sets exporter object fields and generates unique publisher_id.
875+
<p>init: Sets exporter object fields and generates unique publisher_id.
844876
Allows for specification of redis host/port. Also allows runner
845877
hostname to be inputted manually (otherwise will default to
846878
platform.node() value)</p></div>
@@ -865,7 +897,7 @@ <h3>Methods</h3>
865897
log_level: str = &#34;INFO&#34;,
866898
) -&gt; None:
867899
&#34;&#34;&#34;
868-
Sets exporter object fields and generates unique publisher_id.
900+
init: Sets exporter object fields and generates unique publisher_id.
869901
Allows for specification of redis host/port. Also allows runner
870902
hostname to be inputted manually (otherwise will default to
871903
platform.node() value)
@@ -1001,10 +1033,11 @@ <h3>Methods</h3>
10011033
is reached (default = 20s). Returns one of the below result codes based on
10021034
signal publish/response success.
10031035

1004-
RESULT CODES:
1005-
ALL_SUBS_SUCCESS = 0 = ALL SUBS RESPONDED WELL
1006-
SUB_FAILED = 1 = ONE OR MORE SUB RESPONDED BADLY
1007-
MISSING_RESPONE = 2 = NOT ALL SUBS RESPONDED
1036+
Result Codes:
1037+
1038+
- ALL_SUBS_SUCCESS = 0 = all subs responded well
1039+
- SUB_FAILED = 1 = one or more sub responded badly
1040+
- MISSING_RESPONE = 2 = not all subs responded
10081041
&#34;&#34;&#34;
10091042
if not isinstance(timeout, int):
10101043
raise TypeError(&#34;&#39;timeout&#39; arg must be an int value&#34;)
@@ -1137,10 +1170,13 @@ <h3>Methods</h3>
11371170
subscribed responders (if any). The method will give up once the timeout period
11381171
is reached (default = 20s). Returns one of the below result codes based on
11391172
signal publish/response success.</p>
1140-
<p>RESULT CODES:
1141-
ALL_SUBS_SUCCESS = 0 = ALL SUBS RESPONDED WELL
1142-
SUB_FAILED = 1 = ONE OR MORE SUB RESPONDED BADLY
1143-
MISSING_RESPONE = 2 = NOT ALL SUBS RESPONDED</p></div>
1173+
<p>Result Codes:</p>
1174+
<ul>
1175+
<li>ALL_SUBS_SUCCESS = 0 = all subs responded well </li>
1176+
<li>SUB_FAILED = 1 = one or more sub responded badly
1177+
</li>
1178+
<li>MISSING_RESPONE = 2 = not all subs responded</li>
1179+
</ul></div>
11441180
<details class="source">
11451181
<summary>
11461182
<span>Expand source code</span>
@@ -1160,10 +1196,11 @@ <h3>Methods</h3>
11601196
is reached (default = 20s). Returns one of the below result codes based on
11611197
signal publish/response success.
11621198

1163-
RESULT CODES:
1164-
ALL_SUBS_SUCCESS = 0 = ALL SUBS RESPONDED WELL
1165-
SUB_FAILED = 1 = ONE OR MORE SUB RESPONDED BADLY
1166-
MISSING_RESPONE = 2 = NOT ALL SUBS RESPONDED
1199+
Result Codes:
1200+
1201+
- ALL_SUBS_SUCCESS = 0 = all subs responded well
1202+
- SUB_FAILED = 1 = one or more sub responded badly
1203+
- MISSING_RESPONE = 2 = not all subs responded
11671204
&#34;&#34;&#34;
11681205
if not isinstance(timeout, int):
11691206
raise TypeError(&#34;&#39;timeout&#39; arg must be an int value&#34;)
@@ -1243,7 +1280,7 @@ <h3>Methods</h3>
12431280
Can be used both for listening for signals as well as responding to them. Also
12441281
allows for locking onto specific tags/publisher_ids. Uses the standard signal
12451282
response protocol for all published messages.</p>
1246-
<p>Sets exporter object fields and generates unique responder_id.
1283+
<p>init: Sets responder object fields and generates unique responder_id.
12471284
Allows for specification of redis host/port.</p></div>
12481285
<details class="source">
12491286
<summary>
@@ -1265,7 +1302,7 @@ <h3>Methods</h3>
12651302
log_level=&#34;INFO&#34;,
12661303
) -&gt; None:
12671304
&#34;&#34;&#34;
1268-
Sets exporter object fields and generates unique responder_id.
1305+
init: Sets responder object fields and generates unique responder_id.
12691306
Allows for specification of redis host/port.
12701307
&#34;&#34;&#34;
12711308
self.logger = _create_logger(&#34;SignalResponder&#34;, responder_name, log_level)

state_signals.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
from dataclasses import dataclass
2-
from enum import Enum
3-
from typing import Any, Dict, Iterator, List, Optional, Tuple
4-
import redis
5-
import platform
6-
import json
7-
import time
8-
import uuid
9-
import logging
10-
11-
121
"""
132
State/Event Signal Module
143
154
Adds two new, simple-to-use objects:
16-
- SignalExporter (for publishing state signals and handling subscribers + responses)
17-
- SignalResponder (for receiving state signals, locking onto publishers, and publishing responses)
5+
6+
- SignalExporter (for publishing state signals and handling subscribers + responses)
7+
- SignalResponder (for receiving state signals, locking onto publishers, and publishing responses)
188
199
Also provides two dataclass specifications:
20-
- Signal (state signal protocol payload definition)
21-
- Response (response protocol payload definition)
10+
11+
- Signal (state signal protocol payload definition)
12+
- Response (response protocol payload definition)
2213
2314
Combining redis pubsub features with state signal + response protocols,
2415
these additions make state signal publishing, subscribing, receiving,
2516
and responding incredibly easy to integrate into any code.
2617
"""
2718

2819

20+
from dataclasses import dataclass
21+
from enum import Enum
22+
from typing import Any, Dict, Iterator, List, Optional, Tuple
23+
import redis
24+
import platform
25+
import json
26+
import time
27+
import uuid
28+
import logging
29+
30+
2931
def _create_logger(
3032
class_name: str, process_name: str, log_level: str
3133
) -> logging.Logger:
@@ -49,6 +51,10 @@ def _create_logger(
4951

5052

5153
class ResultCodes(Enum):
54+
"""
55+
All potential result codes when publishing a signal. See the publish_signal
56+
method under SignalExporter for more details.
57+
"""
5258
ALL_SUBS_SUCCESS = 0
5359
SUB_FAILED = 1
5460
MISSING_RESPONSE = 2
@@ -170,7 +176,7 @@ def __init__(
170176
log_level: str = "INFO",
171177
) -> None:
172178
"""
173-
Sets exporter object fields and generates unique publisher_id.
179+
init: Sets exporter object fields and generates unique publisher_id.
174180
Allows for specification of redis host/port. Also allows runner
175181
hostname to be inputted manually (otherwise will default to
176182
platform.node() value)
@@ -306,10 +312,11 @@ def publish_signal(
306312
is reached (default = 20s). Returns one of the below result codes based on
307313
signal publish/response success.
308314
309-
RESULT CODES:
310-
ALL_SUBS_SUCCESS = 0 = ALL SUBS RESPONDED WELL
311-
SUB_FAILED = 1 = ONE OR MORE SUB RESPONDED BADLY
312-
MISSING_RESPONE = 2 = NOT ALL SUBS RESPONDED
315+
Result Codes:
316+
317+
- ALL_SUBS_SUCCESS = 0 = all subs responded well
318+
- SUB_FAILED = 1 = one or more sub responded badly
319+
- MISSING_RESPONE = 2 = not all subs responded
313320
"""
314321
if not isinstance(timeout, int):
315322
raise TypeError("'timeout' arg must be an int value")
@@ -409,7 +416,7 @@ def __init__(
409416
log_level="INFO",
410417
) -> None:
411418
"""
412-
Sets exporter object fields and generates unique responder_id.
419+
init: Sets responder object fields and generates unique responder_id.
413420
Allows for specification of redis host/port.
414421
"""
415422
self.logger = _create_logger("SignalResponder", responder_name, log_level)

0 commit comments

Comments
 (0)