Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to configure topic in consumer #427

Open
glensc opened this issue Jun 21, 2017 · 2 comments
Open

unable to configure topic in consumer #427

glensc opened this issue Jun 21, 2017 · 2 comments

Comments

@glensc
Copy link
Contributor

glensc commented Jun 21, 2017

i created myself a consumer using @ralphbean gist: https://gist.github.com/ralphbean/3766683

it has topic hardcoded:

    # I'm only interested in messages from FAS
    topic = "org.fedoraproject.stg.fas*"

but i wanted it to be configurable.

they only way i'm sure method is called is by defining __init__ and assign value there:

class MyTestConsumer(fedmsg.consumers.FedmsgConsumer):

    def __init__(self, hub):
        super(fedmsg.consumers.FedmsgConsumer, self).__init__(hub)
        topic = self.hub.config.get('my_consumer_topic')

however, this emits error, like half of the __init__ is not called:

Traceback (most recent call last):
  File "/usr/share/python2.7/site-packages/moksha/hub/api/consumer.py", line 198, in _work
  File "/usr/share/python2.7/site-packages/fedmsg/consumers/__init__.py", line 271, in post_consume
  File "/usr/share/python2.7/site-packages/fedmsg/consumers/__init__.py", line 275, in save_status
AttributeError: 'CVS2JiraConsumer' object has no attribute 'status_filename'

so like fedmsg/consumers/__init__.py:L114 never called.

and if i look fedmsg/consumers/__init__.py:97-98 seems that __init__ is invoking itself? i'm no Python guru, what's the trick there.

anywho, perhaps add support for calling consumer init, so could do extra initiaization required by consumer?

class MyTestConsumer(fedmsg.consumers.FedmsgConsumer):
    config_key = "cvs2jira_consumer_enabled"

    def configure(self):
        topic = self.hub.config.get('my_consumer_topic')
        pass
glensc added a commit to glensc/fedmsg that referenced this issue Jun 21, 2017
@jeremycline
Copy link
Member

and if i look fedmsg/consumers/init.py:97-98 seems that init is invoking itself? i'm no Python guru, what's the trick there.

The call to super gets the parent class (in this case it's just moksha.hub.api.consumer.Consumer) and calls its __init__ method. I think your problem is in

class MyTestConsumer(fedmsg.consumers.FedmsgConsumer):

    def __init__(self, hub):
        super(fedmsg.consumers.FedmsgConsumer, self).__init__(hub)
        topic = self.hub.config.get('my_consumer_topic')

Try replacing super(fedmsg.consumers.FedmsgConsumer, self).__init__(hub) with super(MyTestConsumer, self).__init__(hub). In your current snippet you're calling the parent of FedmsgConsumer rather than the parent of your class (FedmsgConsumer).

@glensc
Copy link
Contributor Author

glensc commented Jun 21, 2017

yeah, i invoked parent constructor wrong way, but nevertheless, i think the separate configure method would be useful, in the related PR. more cleaner code and api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants