AlecAivazis / graphql-over-kafka

A framework for building event-driven microservice applications in python
MIT License
19 stars 3 forks source link

move ServiceConfig to service_config.py module #38

Closed janjaapbos closed 8 years ago

janjaapbos commented 8 years ago

It is not possible to change the default ServiceConfig when importing a service, since at the import of the service module (needed to access ServiceConfig) the service is immediately created.

It would be better to have the ServiceConfig live in a separate module, e.g. service_config.py

Then we can first import service_config, assign another URI to ServiceConfig, and subsequently import the service.

AlecAivazis commented 8 years ago

Change it from where? Do you mind showing me a use case?

janjaapbos commented 8 years ago

I was playing around with the example services, and wanted use a different sqlalchemy URI, but saw that it was not possbile to change URI before the service was initialized.

See examples/services/recipes.py:

` from sqlalchemy import Column, Text from nautilus.models import HasID, BaseModel, CRUDNotificationCreator

class Recipe(CRUDNotificationCreator, HasID, BaseModel): name = Column(Text)

class ServiceConfig: SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/recipes.db'

service = ModelService( model = Recipe, configObject = ServiceConfig, ) `

Now, looking at it again, when you want to import this service, you might actually also have other requirements for the Recipe class. Perhaps it is better to do this in an init function:

service = ModelService( model = Recipe, configObject = ServiceConfig, )

Anyway, perhaps these files / objects are not meant to be imported. In that case you can close this issue.

AlecAivazis commented 8 years ago

So my problem with importing a service and changing its configuration externally is that you would quickly find yourself in an awkward state where you've changed the configuration from the point of view of an external service without actually changing the internal configuration. Sorry if that's not very clear, I can't try to explain it again.

In short, I don't think services should be imported from other services except in places where the external services are needed to support the intended behavior (like in the case of ConnectionServices). Any sort of configuration should happen in the service definition and other services could look at its configuration if necessary.

AlecAivazis commented 8 years ago

I'm going to close this since I don't think it will result in a change - feel free to continue the discussion, just trying to keep things tidy. We can always reopen it if you end up changing my mind (again)