-
Notifications
You must be signed in to change notification settings - Fork 30
Conversation
d484b84
to
5782c00
Compare
5782c00
to
fd11344
Compare
As I've said in another issue, I apologize for the huge delay in looking at this. The day job has not only taken a lot of my attention, but also my ability to look at "not Python" 😄 I'll dive in and get this merged ASAP - as always, your contributions are 💯 |
No worries at all, I know how that goes. I did a bunch of refactor branches back when I was still between jobs. They all build on one another so I was going to submit them one at a time. I can continue doing that or I can hold off if you prefer. I enjoy the refactoring process even if the changes are never merged, so I don't consider it wasted time or anything of that nature. |
// NewAgentComms returns a comms instance configured for agent usages. | ||
// | ||
// TODO: accept an interface for cache instead of concrete type | ||
func NewAgentComms(cfg config.Config, ac *cache.AgentCache) (*toddComms, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed you changed the reference to NewToDDComms
to point here instead (in https://github.com/toddproject/todd/pull/126/files#diff-8a0edf5a42325103a551ddd3ac9616c8R79) but left the old NewToDDComms
function.
Is the intention to eventually retire NewToDDComms
, but just didn't want to bloat this PR? If so, a comment indicating so would be appreciated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, I was trying to limit the scope of the changes to the agent/cache
package as much as possible. At the time comms needed access to the agent cache, but only when being used by the agent, so I did the simple thing and added a special constructor just for the agent. The server and client still use NewToDDComms
.
I didn't add a comment because I wasn't sure what was temporary and what wasn't. I did know that the Package.setAgentCache()
method need to be removed eventually, so that did get a comment. As it turned out, when I got to the comms package in my refactor-comms
branch, the agent cache dependency was decoupled from comms and I collapsed both constructors and renamed them to simply New()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for the refactoring efforts dude. Watching you remove all of those initializations and setup calls since you're doing them once at the beginning was like watching a hot knife go through butter. Fantastic
Just one inline comment, dependent on your plans for some of the changes. Other than that LGTM
github.com/pkg/errors
as discussed in Proposal: Error handling with pkg/errors #82.fmt.Sprintf
withfilepath.Join
, which handles cross-platform paths.AgentCache
only opens the database once at start instead of on every call. (sql.DB
is a connection pool safe for concurrent use.)AgentCache
is initialized incmd/todd-agent/main.go
and injected into functions/objects which require it, namelyTask.Run()
. As a temporary measure, thesetAgentCache()
method was added to thecomms
package so todd-agent can inject theAgentCache
. This is to avoid too many change in this patch and is removed in a later patch where task handling is largely extracted fromcomms
.NewAgentCache()
andAgentCache.Init()
intoNew()
.Usage appears as
cache.New(cfg)
instead ofcache.NewAgentCache()
, this is recommended when a package only exports one type. (As mentioned in Effective Go.)The two steps were combined as there is no case of creating an
AgentCache
and not immediately initializing it.AgentCache.SetKeyValue()
.