Improve reliability and quality of the system
namespace #1
Loading…
Reference in New Issue
No description provided.
Delete Branch "seabass/matchbot:system-improvements"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
@ -39,4 +37,1 @@
:state nil
:irc nil})
(defn start [system]
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.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.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.
Resolved in commit
91cbdb69da
.@ -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))
No reason for this either, I think? As the system value isn't used for
start
, and runningstop
multiple times is safe.I've just made commit
91cbdb69da
- is this what you had in mind?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.
LGTM
Resolved
Thank you for reviewing, @sm2n!