Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues/67 #113

Merged
merged 119 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
46ee44a
f
komuw May 26, 2019
b4656e0
f
komuw May 26, 2019
9be1082
f
komuw May 26, 2019
1a23c30
f
komuw May 26, 2019
71658ea
f
komuw May 26, 2019
7c08721
f
komuw May 26, 2019
4cd9552
f
komuw May 26, 2019
9999505
f
komuw May 26, 2019
2802033
f
komuw May 26, 2019
ac938c3
f
komuw May 26, 2019
6479372
Merge branch 'master' into issues/102
komuw May 26, 2019
5121fce
f
komuw May 26, 2019
d7a693c
f
komuw May 26, 2019
a3fa9a6
f
komuw May 26, 2019
7d5844e
f
komuw May 26, 2019
94c93b2
f
komuw May 26, 2019
9115ff0
f
komuw May 26, 2019
99e8a60
f
komuw May 26, 2019
59b2404
f
komuw May 26, 2019
eb1d91e
f
komuw May 26, 2019
491f5ff
f
komuw May 26, 2019
f113c66
f
komuw May 26, 2019
4ebcfe4
f
komuw May 26, 2019
48271ed
Merge branch 'issues/102' into issues/107
komuw May 26, 2019
3672c91
f
komuw May 26, 2019
d624754
f
komuw May 26, 2019
cc5bba8
f
komuw May 26, 2019
f3d857a
f
komuw May 26, 2019
5616b19
f
komuw May 26, 2019
a8ae37f
Merge branch 'issues/102' into issues/107
komuw May 26, 2019
f3b8235
f
komuw May 26, 2019
7558eba
Merge branch 'issues/102' into issues/107
komuw May 26, 2019
2d64ba3
f
komuw May 27, 2019
bc7365a
f
komuw May 27, 2019
a12c9be
f
komuw May 27, 2019
ec36d29
f
komuw May 27, 2019
910681a
f
komuw May 27, 2019
b3826cf
f
komuw May 27, 2019
aaa60ab
f
komuw May 27, 2019
c61dbc7
Merge branch 'issues/107' into issues/110
komuw May 27, 2019
c15aa33
f
komuw May 27, 2019
83fd356
Merge branch 'issues/107' into issues/110
komuw May 27, 2019
bcefd76
f
komuw May 27, 2019
4abf27a
f
komuw May 27, 2019
c4b0f81
f
komuw May 27, 2019
a20ed89
f
komuw May 27, 2019
796facb
Merge branch 'issues/107' into issues/110
komuw May 27, 2019
41df85b
f
komuw May 27, 2019
d7d76e5
f
komuw May 27, 2019
6ab381c
f
komuw May 27, 2019
d56e72b
Merge branch 'issues/107' into issues/110
komuw May 27, 2019
b350d9c
f
komuw May 27, 2019
2f37534
f
komuw May 27, 2019
336d9d5
f
komuw May 27, 2019
492025f
f
komuw May 27, 2019
3a0aaa5
f
komuw May 28, 2019
6ce1e6e
f
komuw May 28, 2019
a9a161a
f
komuw May 28, 2019
24a808d
f
komuw May 28, 2019
74314f5
f
komuw May 28, 2019
da1c3b4
f
komuw May 28, 2019
031603e
Merge branch 'master' into issues/67
komuw May 28, 2019
459bd0e
f
komuw May 28, 2019
d277a67
f
komuw May 28, 2019
0a8212d
f
komuw May 28, 2019
69b877d
f
komuw May 28, 2019
7e4763c
f
komuw May 28, 2019
ae4bae4
f
komuw May 28, 2019
2b687a2
validate request first
komuw May 29, 2019
f2eead5
f
komuw May 29, 2019
b388f28
f
komuw May 29, 2019
be71c15
f
komuw May 29, 2019
1b5940d
f
komuw May 29, 2019
892bc0b
f
komuw May 29, 2019
996f5cc
f
komuw May 29, 2019
6bbb03e
f
komuw May 29, 2019
b4ddb95
f
komuw May 29, 2019
a2a2554
f
komuw May 29, 2019
00fdd60
f
komuw May 29, 2019
b8b8d81
f
komuw May 30, 2019
def7ba8
f
komuw May 31, 2019
d0f3e53
f
komuw May 31, 2019
7324801
f
komuw May 31, 2019
c367b26
f
komuw May 31, 2019
8d5c55d
f
komuw May 31, 2019
7621e2e
f
komuw May 31, 2019
30f4fc2
f
komuw May 31, 2019
0c7067c
f
komuw May 31, 2019
0fcd4b0
f
komuw May 31, 2019
eefd810
f
komuw May 31, 2019
3b376ac
f
komuw May 31, 2019
a14517b
f
komuw May 31, 2019
c36f124
f
komuw May 31, 2019
6ccd137
f
komuw May 31, 2019
00f02ea
f
komuw May 31, 2019
694fd80
f
komuw May 31, 2019
195274b
f
komuw May 31, 2019
9e18e7f
f
komuw May 31, 2019
3c0f9bf
f
komuw May 31, 2019
c4cc2fe
f
komuw May 31, 2019
7538b5a
f
komuw May 31, 2019
0a95a97
f
komuw May 31, 2019
0e1587b
f
komuw May 31, 2019
bcc9806
f
komuw May 31, 2019
b90fba2
f
komuw May 31, 2019
7a9a2ff
f
komuw May 31, 2019
97445aa
f
komuw May 31, 2019
3965451
f
komuw May 31, 2019
e28a670
f
komuw May 31, 2019
1ea8a67
f
komuw May 31, 2019
8574ff5
f
komuw May 31, 2019
16e7520
f
komuw May 31, 2019
8eeca89
f
komuw May 31, 2019
ebc99b5
f
komuw May 31, 2019
7adb291
f
komuw May 31, 2019
9148e18
f
komuw May 31, 2019
66c5f90
f
komuw May 31, 2019
2928f2c
f
komuw May 31, 2019
6053a50
f
komuw May 31, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ script:
- naz-cli --version && naz-cli --help
- naz-cli --config examples/example_config.json --dry-run
- coverage erase
- export CI_ENVIRONMENT=Yes && coverage run --omit="*tests*,*cli/test_*,*examples/*,*.virtualenvs/*,*virtualenv/*,*.venv/*,*__init__*" -m unittest discover -v -s . && bash <(curl -s https://codecov.io/bash)
- coverage report --show-missing --fail-under=83
- export CI_ENVIRONMENT=Yes && coverage run --omit="*tests*,*examples/*,*.virtualenvs/*,*virtualenv/*,*.venv/*,*__init__*" -m unittest discover -v -s . && bash <(curl -s https://codecov.io/bash)
- coverage report --show-missing --fail-under=84
- |
git remote set-branches --add origin master # https://github.com/travis-ci/travis-ci/issues/6069
git fetch
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ most recent version is listed first.
- cleanly handle termination signals like `SIGTERM`: https://github.com/komuw/naz/pull/106
- validate `naz.Client` arguments: https://github.com/komuw/naz/pull/108
- remove ability to bring your own eventloop: https://github.com/komuw/naz/pull/111
- make `naz` more fault tolerant: https://github.com/komuw/naz/pull/113
- `naz` now has a configurable timeout when trying to connect to SMSC
- `naz` will now be able to detect when the connection to SMSC is disconnected and will attempt to re-connect & re-bind
- bugfix; `asyncio.streams.StreamWriter.drain` should not be called concurrently by multiple coroutines
- when shutting down, `naz` now tries to make sure that write buffers are properly flushed.

## **version:** v0.6.0-beta.1
- Bug fix: https://github.com/komuw/naz/pull/98
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ test:
@export PYTHONASYNCIODEBUG='2'
@printf "\n removing pyc files::\n" && find . -name '*.pyc' -delete;find . -name '__pycache__' -delete | xargs echo
@printf "\n coverage erase::\n" && coverage erase
@printf "\n coverage run::\n" && coverage run --omit="*tests*,*cli/test_*,*examples/*,*.virtualenvs/*,*virtualenv/*,*.venv/*,*__init__*" -m unittest discover -v -s .
@printf "\n coverage report::\n" && coverage report --show-missing --fail-under=83
@printf "\n coverage report html::\n" && coverage html --fail-under=83 --title=naz_coverage
@printf "\n coverage run::\n" && coverage run --omit="*tests*,*examples/*,*.virtualenvs/*,*virtualenv/*,*.venv/*,*__init__*" -m unittest discover -v -s .
@printf "\n coverage report::\n" && coverage report --show-missing --fail-under=84
@printf "\n coverage report html::\n" && coverage html --fail-under=84 --title=naz_coverage
@printf "\n run flake8::\n" && flake8 .
@printf "\n run pylint::\n" && pylint --enable=E --disable=W,R,C examples/ naz/ tests/ cli/ documentation/
@printf "\n run bandit::\n" && bandit -r --exclude .venv -ll .
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ loop.run_until_complete(cli.tranceiver_bind())

try:
# read any data from SMSC, send any queued messages to SMSC and continually check the state of the SMSC
tasks = asyncio.gather(cli.send_forever(), cli.receive_data(), cli.enquire_link())
tasks = asyncio.gather(cli.dequeue_messages(), cli.receive_data(), cli.enquire_link())
loop.run_until_complete(tasks)
loop.run_forever()
except Exception as e:
Expand Down Expand Up @@ -138,7 +138,7 @@ run:
{'event': 'naz.SimpleHook.request', 'stage': 'start', 'smpp_command': 'bind_transceiver', 'log_id': None, 'environment': 'production', 'release': 'canary', 'smsc_host': '127.0.0.1', 'system_id': 'smppclient1', 'client_id': '2VU55VT86KHWXTW7X'}
{'event': 'naz.Client.send_data', 'stage': 'end', 'smpp_command': 'bind_transceiver', 'log_id': None, 'msg': 'hello', 'environment': 'production', 'release': 'canary', 'smsc_host': '127.0.0.1', 'system_id': 'smppclient1', 'client_id': '2VU55VT86KHWXTW7X'}
{'event': 'naz.Client.tranceiver_bind', 'stage': 'end', 'environment': 'production', 'release': 'canary', 'smsc_host': '127.0.0.1', 'system_id': 'smppclient1', 'client_id': '2VU55VT86KHWXTW7X'}
{'event': 'naz.Client.send_forever', 'stage': 'start', 'environment': 'production', 'release': 'canary', 'smsc_host': '127.0.0.1', 'system_id': 'smppclient1', 'client_id': '2VU55VT86KHWXTW7X'}
{'event': 'naz.Client.dequeue_messages', 'stage': 'start', 'environment': 'production', 'release': 'canary', 'smsc_host': '127.0.0.1', 'system_id': 'smppclient1', 'client_id': '2VU55VT86KHWXTW7X'}
```

**NB:**
Expand Down Expand Up @@ -331,7 +331,7 @@ loop.run_until_complete(cli.tranceiver_bind())

try:
# read any data from SMSC, send any queued messages to SMSC and continually check the state of the SMSC
tasks = asyncio.gather(cli.send_forever(), cli.receive_data(), cli.enquire_link())
tasks = asyncio.gather(cli.dequeue_messages(), cli.receive_data(), cli.enquire_link())
loop.run_until_complete(tasks)
loop.run_forever()
except Exception as e:
Expand Down Expand Up @@ -398,7 +398,7 @@ reader, writer = loop.run_until_complete(cli.connect())
loop.run_until_complete(cli.tranceiver_bind())
try:
# read any data from SMSC, send any queued messages to SMSC and continually check the state of the SMSC
tasks = asyncio.gather(cli.send_forever(), cli.receive_data(), cli.enquire_link())
tasks = asyncio.gather(cli.dequeue_messages(), cli.receive_data(), cli.enquire_link())
loop.run_until_complete(tasks)
loop.run_forever()
except Exception as e:
Expand Down
38 changes: 24 additions & 14 deletions cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,27 +212,37 @@ def main():
return

# call naz api
cli = naz.Client(**kwargs)
# connect to the SMSC host
_, _ = loop.run_until_complete(cli.connect())
# bind to SMSC as a tranceiver
loop.run_until_complete(cli.tranceiver_bind())

# read any data from SMSC, send any queued messages to SMSC and continually check the state of the SMSC
tasks = asyncio.gather(
cli.send_forever(TESTING=dry_run),
cli.receive_data(TESTING=dry_run),
cli.enquire_link(TESTING=dry_run),
sig._signal_handling(logger=logger, client=cli, loop=loop),
loop=loop,
client = naz.Client(**kwargs)
loop.run_until_complete(
async_main(client=client, logger=logger, loop=loop, dry_run=dry_run)
)
loop.run_until_complete(tasks)
except Exception as e:
logger.log(logging.ERROR, {"event": "naz.cli.main", "stage": "end", "error": str(e)})
sys.exit(77)
finally:
logger.log(logging.INFO, {"event": "naz.cli.main", "stage": "end"})


async def async_main(
client: naz.Client,
logger: naz.logger.SimpleLogger,
loop: asyncio.events.AbstractEventLoop,
dry_run: bool,
):
# connect & bind to the SMSC host
await client.connect()
await client.tranceiver_bind()

# send any queued messages to SMSC, read any data from SMSC and continually check the state of the SMSC
tasks = asyncio.gather(
client.dequeue_messages(TESTING=dry_run),
client.receive_data(TESTING=dry_run),
client.enquire_link(TESTING=dry_run),
sig._signal_handling(logger=logger, client=client, loop=loop),
loop=loop,
)
await tasks


if __name__ == "__main__":
main()
7 changes: 4 additions & 3 deletions documentation/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ loglevel | the level at which to log | INFO
log_metadata | metadata that will be included in all log statements | {"smsc_host": smsc_host, "system_id": system_id}
codec_class | python class instance to be used to encode/decode messages | naz.nazcodec.SimpleNazCodec
codec_errors_level | same meaning as the `errors` argument to pythons' `encode` method as [defined here](https://docs.python.org/3/library/codecs.html#codecs.encode) | strict
enquire_link_interval | time in seconds to wait before sending an `enquire_link` request to SMSC to check on its status | 90
enquire_link_interval | time in seconds to wait before sending an `enquire_link` request to SMSC to check on its status | 55.0
rateLimiter | python class instance implementing rate limitation | naz.ratelimiter.SimpleRateLimiter
hook | python class instance implemeting functionality/hooks to be called by `naz` just before sending request to SMSC and just after getting response from SMSC | naz.hooks.SimpleHook
throttle_handler | python class instance implementing functionality of what todo when naz starts getting throttled responses from SMSC | naz.throttle.SimpleThrottleHandler
correlation_handler | A python class instance that naz uses to store relations between SMPP sequence numbers and user applications' log_id's and/or hook_metadata. | naz.correlater.SimpleCorrelater
drain_duration | duration in seconds that `naz` will wait for after receiving a termination signal. | 8.00
drain_duration | duration in seconds that `naz` will wait for after receiving a termination signal. | 8.00
connect_timeout | duration that `naz` will try to connect to SMSC before timing out | 30.00

`SMSC`: Short Message Service Centre, ie the server
`ESME`: External Short Message Entity, ie the client
Expand All @@ -84,7 +85,7 @@ drain_duration | duration in seconds that `naz` will wait for after receiving a
"release": "canary"
},
"codec_errors_level": "ignore",
"enquire_link_interval": 30,
"enquire_link_interval": 30.0,
"rateLimiter": "dotted.path.to.CustomRateLimiter"
}
```
Expand Down
4 changes: 2 additions & 2 deletions documentation/sphinx-docs/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ naz is in active development and it's API may change in backward incompatible wa

try:
# read any data from SMSC, send any queued messages to SMSC and continually check the state of the SMSC
tasks = asyncio.gather(cli.send_forever(), cli.receive_data(), cli.enquire_link())
tasks = asyncio.gather(cli.dequeue_messages(), cli.receive_data(), cli.enquire_link())
loop.run_until_complete(tasks)
loop.run_forever()
except Exception as e:
Expand Down Expand Up @@ -373,7 +373,7 @@ An example of using that queue;

try:
# read any data from SMSC, send any queued messages to SMSC and continually check the state of the SMSC
tasks = asyncio.gather(cli.send_forever(), cli.receive_data(), cli.enquire_link())
tasks = asyncio.gather(cli.dequeue_messages(), cli.receive_data(), cli.enquire_link())
loop.run_until_complete(tasks)
loop.run_forever()
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion examples/example_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"release": "canary"
},
"codec_errors_level": "ignore",
"enquire_link_interval": 70,
"enquire_link_interval": 70.00,
"rateLimiter": "examples.example_klasses.ExampleRateLimiter"
}
2 changes: 1 addition & 1 deletion examples/in_mem_queue_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

try:
# read any data from SMSC, send any queued messages to SMSC and continually check the state of the SMSC
tasks = asyncio.gather(cli.send_forever(), cli.receive_data(), cli.enquire_link())
tasks = asyncio.gather(cli.dequeue_messages(), cli.receive_data(), cli.enquire_link())
loop.run_until_complete(tasks)
loop.run_forever()
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions examples/rabbitmq_queue_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def blocking_dequeue(self):
system_id="smppclient1",
password=os.getenv("password", "password"),
outboundqueue=outboundqueue,
enquire_link_interval=17,
enquire_link_interval=17.00,
)

item_to_enqueue = {
Expand All @@ -148,7 +148,7 @@ def blocking_dequeue(self):

try:
# read any data from SMSC, send any queued messages to SMSC and continually check the state of the SMSC
tasks = asyncio.gather(cli.send_forever(), cli.receive_data(), cli.enquire_link())
tasks = asyncio.gather(cli.dequeue_messages(), cli.receive_data(), cli.enquire_link())
loop.run_until_complete(tasks)
loop.run_forever()
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion examples/redis_queue_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def blocking_dequeue(self):

try:
# read any data from SMSC, send any queued messages to SMSC and continually check the state of the SMSC
tasks = asyncio.gather(cli.send_forever(), cli.receive_data(), cli.enquire_link())
tasks = asyncio.gather(cli.dequeue_messages(), cli.receive_data(), cli.enquire_link())
loop.run_until_complete(tasks)
loop.run_forever()
except Exception as e:
Expand Down
Loading