Improve reliability and quality of the system namespace #1

Merged
seabass merged 4 commits from seabass/matchbot:system-improvements into master 2022-03-26 15:05:32 +01:00
Owner

This pull request improves the system namespace, fixing a non-critical bug in the system's start/stop mechanism and removing unnecessary code.

Commits

Remove use of state container in main function

Since the main function will only ever start and stop one system, this commit simplifies the main function to use a single lexical binding for the system state rather than creating an Atom.

Remove unnecessary system/system function

A nil value acts as an empty map wherever a map value is expected. For this reason, this commit removes the system/system function (which returns an empty map), since a call to it can safely be replaced with a nil value.

Use a Var instead of an Atom for system state

The Atom's swap! function may run its provided function multiple times. Because of this, using an Atom for the system state can occasionally result in duplicate TCP connections being opened when the system is started. These connections remain open until they timeout (this is typically 5 minutes for IRC).

This commit changes the container for the system state from an Atom to a Var, whose alter-var-root function (analogous to swap!) does not have this issue.

This pull request improves the `system` namespace, fixing a non-critical bug in the system's start/stop mechanism and removing unnecessary code. # Commits ## [Remove use of state container in main function](https://git.libregaming.org/seabass/matchbot/commit/56094478dbe5398d6a8524e8bee5339ab814737e) Since the main function will only ever start and stop one system, this commit simplifies the main function to use a single lexical binding for the system state rather than creating an Atom. ## [Remove unnecessary system/system function](https://git.libregaming.org/seabass/matchbot/commit/fecd09c65624afef5565d7120421891a948a8643) A nil value acts as an empty map wherever a map value is expected. For this reason, this commit removes the system/system function (which returns an empty map), since a call to it can safely be replaced with a nil value. ## [Use a Var instead of an Atom for system state](https://git.libregaming.org/seabass/matchbot/commit/0abd793fe7b6bd83d62a7b3f690a22d549723b55) The Atom's swap! function may run its provided function multiple times. Because of this, using an Atom for the system state can occasionally result in duplicate TCP connections being opened when the system is started. These connections remain open until they timeout (this is typically 5 minutes for IRC). This commit changes the container for the system state from an Atom to a Var, whose alter-var-root function (analogous to swap!) does not have this issue.
seabass added 3 commits 2022-03-23 00:10:29 +01:00
56094478db Remove use of state container in main function
Since the main function will only ever start and stop one system, this
commit simplifies the main function to use a single lexical binding for
the system state rather than creating an Atom.

Signed-off-by: Sebastian Crane <seabass-labrax@gmx.com>
0abd793fe7 Use a Var instead of an Atom for system state
The Atom's swap! function may run its provided function multiple
times. Because of this, using an Atom for the system state can
occasionally result in duplicate TCP connections being opened when the
system is started. These connections remain open until they
timeout (this is typically 5 minutes for IRC).

This commit changes the container for the system state from an Atom to a
Var, whose alter-var-root function (analogous to swap!) does not have
this issue.

Signed-off-by: Sebastian Crane <seabass-labrax@gmx.com>
fecd09c656 Remove unnecessary system/system function
A nil value acts as an empty map wherever a map value is expected. For
this reason, this commit removes the system/system function (which
returns an empty map), since a call to it can safely be replaced with a
nil value.

Signed-off-by: Sebastian Crane <seabass-labrax@gmx.com>
seabass requested review from sm2n 2022-03-23 00:10:53 +01:00
sm2n requested changes 2022-03-23 20:49:30 +01:00
Dismissed
src/system.clj Outdated
@ -39,4 +37,1 @@
:state nil
:irc nil})
(defn start [system]
Owner

start doesn't actually use its input as far as I can tell? I think it'd be better to use _ as the binding name here since that is the case.

`start` doesn't actually use its input as far as I can tell? I think it'd be better to use _ as the binding name here since that is the case.
Author
Owner

I was imagining that, in the future, this could be used to pass custom options to a single instance for development purposes, and also eventually for the main function to read the config and pass it in rather than system/start doing it by itself. Do you have any preference here? For now, yes, I agree it would be better to use _ as the binding name.

I was imagining that, in the future, this could be used to pass custom options to a single instance for development purposes, and also eventually for the main function to read the config and pass it in rather than `system/start` doing it by itself. Do you have any preference here? For now, yes, I agree it would be better to use `_` as the binding name.
Owner

No, I don't have a preference here. I think what you said makes sense with regards to custom options etc. Feel free to mark this resolved.

No, I don't have a preference here. I think what you said makes sense with regards to custom options etc. Feel free to mark this resolved.
Author
Owner

Resolved in commit 91cbdb69da.

Resolved in commit 91cbdb69da.
sm2n marked this conversation as resolved
src/system.clj Outdated
@ -61,2 +55,2 @@
(reset! system-atom (system))
(swap! system-atom start)))
(alter-var-root system-var stop)
(alter-var-root system-var (constantly nil))
Owner

No reason for this either, I think? As the system value isn't used for start, and running stop multiple times is safe.

No reason for this either, I think? As the system value isn't used for `start`, and running `stop` multiple times is safe.
Author
Owner

I've just made commit 91cbdb69da - is this what you had in mind?

I've just made commit 91cbdb69da - is this what you had in mind?
sm2n marked this conversation as resolved
seabass added this to the 1.0.1 milestone 2022-03-23 20:56:32 +01:00
seabass added 1 commit 2022-03-24 23:06:08 +01:00
91cbdb69da Simplify the system start and restart functions
This commit changes the binding name of system/start's argument to
_ (since it is currently not used within the function), and simplifies
the system/restart function by not swapping the system Var's content
with nil before filling it with the new-created system state.

Eventually, these changes will be reverted when the initialisation of
the system is separated from the starting of that system, which will
mean that system/start will read its argument and that system/restart
will have to reinitialise the system state before restarting it.

Signed-off-by: Sebastian Crane <seabass-labrax@gmx.com>
Author
Owner

Simplify the system start and restart functions

This commit changes the binding name of system/start's argument to _ (since it is currently not used within the function), and simplifies the system/restart function by not swapping the system Var's content with nil before filling it with the new-created system state.

Eventually, these changes will be reverted when the initialisation of the system is separated from the starting of that system, which will mean that system/start will read its argument and that system/restart will have to reinitialise the system state before restarting it.

## [Simplify the system start and restart functions](https://git.libregaming.org/LibreGaming/matchbot/commit/91cbdb69daf66e7077255fd69b206ef4d3ac4eab) This commit changes the binding name of system/start's argument to _ (since it is currently not used within the function), and simplifies the system/restart function by not swapping the system Var's content with nil before filling it with the new-created system state. Eventually, these changes will be reverted when the initialisation of the system is separated from the starting of that system, which will mean that system/start will read its argument and that system/restart will have to reinitialise the system state before restarting it.
seabass requested review from sm2n 2022-03-24 23:10:07 +01:00
Owner

LGTM

LGTM
seabass removed review request for sm2n 2022-03-26 15:02:50 +01:00
seabass dismissed sm2n’s review 2022-03-26 15:03:35 +01:00
Reason:

Resolved

Author
Owner

Thank you for reviewing, @sm2n!

Thank you for reviewing, @sm2n!
seabass merged commit 91cbdb69da into master 2022-03-26 15:05:32 +01:00
Sign in to join this conversation.
No reviewers
No Label
security
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: LibreGaming/matchbot#1
No description provided.