UltrosBot / Ultros

Connecting communities, one squid at a time! Ultros is a multi-protocol chat bot written in Python, designed with both the user and developer in mind
http://ultros.io
Artistic License 2.0
23 stars 7 forks source link

Unfuck factories #90

Closed gdude2002 closed 8 years ago

gdude2002 commented 8 years ago

Here's the current path we take when we connect a protocol.

Twisted, however, expects something like this:

What would be our ideal path? Let's fix that and make it happen! As a side effect, this ticket will result in protocols having their own factories, which is a requirement for all kinds of things.

gdude2002 commented 8 years ago

In my opinion, I think we should do something like..

rakiru commented 8 years ago

What would setup() do exactly? Isn't everything covered by connect() and buildProtocol()?

gdude2002 commented 8 years ago

Ah, hm, yeah, I suppose that's all one would need.. I can't think of anything I'd put in setup() that would be bad to run more than once.

rakiru commented 8 years ago

Why would we run more than once? Isn't the point that connect/setup() gets called once to start it, and buildProtocol() gets called on each connection? What needs done other than building the protocol? Reloading it, but that's currently done at protocol build time anyway.

gdude2002 commented 8 years ago

It would be run again if the connection fails or is lost, of course. Not all factories would be calling the same reactor.connect<proto>(...) function with the same args, and we need some generic way of doing this if we want to have reconnect management in the base protocol.

rakiru commented 8 years ago

When would connect() be called other than to begin with though? ClientFactory already has a way to deal with this. Considering ReconnectingClientFactory. You only call reactor.connect... on it once, then it uses the connector to schedule a reconnect when clientConnectionLost/Failed is called.

gdude2002 commented 8 years ago

OK, sure, but then the protocol instance gets reused - do we want that?

rakiru commented 8 years ago

What? It calls buildProtocol()...

gdude2002 commented 8 years ago

Oh, it does? I didn't know that. Alright then, then... yeah. That.

gdude2002 commented 8 years ago

Time for another draft, I guess.

rakiru commented 8 years ago

What's the point of setup()? Isn't that the point of __init__()? Better reconnect logic (re. timing) would be a good idea. If we need to keep track of the Protocol instance anyway, no point breaking the API by renaming protocol attribute.

gdude2002 commented 8 years ago

Forgot to rename to connect(). :P

gdude2002 commented 8 years ago

Progress on this is progressing nicely. Couldn't think of a better way to put that.

@rakiru I think you're good to review the commits so far.

gdude2002 commented 8 years ago

We're done - #91