Issue in Pybossa webhooks, how to execute it

孤街浪徒 提交于 2019-12-11 05:12:37

问题


I am working with the Pybossa webhooks, and found this plugin to analyse the Pybossa results in real-time. I forked it but not getting how it is to be executed.

Currently, I am executing it as follows:

python app.py test_project

where test_project is my project_short_name. But, it is reverting me to index.html page of this repository.


回答1:


I found it ! Look into pybossa.model.event_listeners you will find push_webhookfunction, it push webhook into queue. And it's called by on_taskrun_submit, on_auditrun_submit function in the same file.

If you really want to execute webhook manually, look into pybossa.jobs, you will find webhook function, it's where the webhook execute. You can call it manually like this:

def trigger_webhook(short_name, task_id=0, result_id=0):
    from pybossa.jobs import webhook
    from datetime import datetime
    from pybossa.core import project_repo

    with app.app_context():
        project = project_repo.get_by_shortname(short_name)

        payload = dict(event="task_completed",
                       project_short_name=project.short_name,
                       project_id=project.id,
                       task_id=task_id,
                       result_id=result_id,
                       fired_at=datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"))
        webhook(project.webhook, payload)

I put this function in cli.py so I can call it handily.




回答2:


I haven't set it up myself, but it would seem you run both the primary Pybossa site in addition to a custom microservice you can fork from the webhooks project.

  1. Install and run the primary Pybossa server and create an admin account.
  2. Install and run webhooks fork
  3. Grab your API key from an admin's account page on your primary PyBossa server.
  4. In webhooks, Clone the settings.py.tmpl and update the information such as API key.
  5. Run the microservice.
  6. In Pybossa, Configure your project to use the webhook URL in your settings.
  7. In webhooks, load the index.html page.

You would change the charts on the index page to display the results you're interested in. But like I said, this is just what I understand needs to be done. I haven't done it myself as I'm just going to modify the presenter JS to use the API to perform some operations I desire dependent on value of submitted answer. Best of luck.



来源:https://stackoverflow.com/questions/41344811/issue-in-pybossa-webhooks-how-to-execute-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!