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

trigger tool #155

Open
nirik opened this issue Apr 12, 2019 · 3 comments
Open

trigger tool #155

nirik opened this issue Apr 12, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@nirik
Copy link
Member

nirik commented Apr 12, 2019

fedmsg has a tool called 'fedmsg-trigger'. It lets you easily do a one command line type thing to run a command/script when a specific message comes accross the bus.

It would be cool if there was something like this for fedora-messaging too.

@abompard abompard added the enhancement New feature or request label Apr 15, 2019
@abompard
Copy link
Member

It is indeed an interesting feature. It can be done with the current code, although not as easily as the fedmsg-trigger command. You'll need to define a callback module like this (for example called run_command.py):

from subprocess import call
from fedora_messaging.config import conf
def run(message):
    call(conf["consumer_config"]["command"], shell=True)

And a configuration file that contains these lines (named for example trigger.toml):

# The module and function name
callback = "run_command:run"
[consumer_config]
command = "echo message received"

The module must be importable, so you may need to set PYTHONPATH, but then you can run the command PYTHONPATH=. fedora-messaging --conf trigger.toml consume and it will execute the command on each received message. You can filter the topics you want to act on by configuring the [[bindings]] section in the configuration file (the routing_keys list is topics or topic patterns).

Would that let you do what you want to do?

@jeremycline
Copy link
Member

@abompard, I was thinking we could add a couple generally useful callbacks to a callbacks.py module (and move the printer out into that) that we document and maintain. That way folks can just write some configuration and not have to deal with writing Python.

It's only tangentially related, but I wonder if we should also allow specifying a Python file instead of only a Python path so folks don't need to deal with packaging.

@abompard
Copy link
Member

Yeah I agree to both propositions.

jeremycline added a commit to jeremycline/fedora-messaging that referenced this issue Apr 17, 2019
Runs a configurable command when a message is received.

Fixes fedora-infra#155

Signed-off-by: Jeremy Cline <jcline@redhat.com>
jeremycline added a commit to jeremycline/fedora-messaging that referenced this issue Apr 17, 2019
Runs a configurable command when a message is received.

Fixes fedora-infra#155

Signed-off-by: Jeremy Cline <jcline@redhat.com>
cverna pushed a commit to jeremycline/fedora-messaging that referenced this issue Mar 10, 2020
Runs a configurable command when a message is received.

Fixes fedora-infra#155

Signed-off-by: Jeremy Cline <jcline@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants