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

Add task scheduling system to metagov-core #19

Closed
gigxz opened this issue Apr 8, 2021 · 5 comments · Fixed by #42
Closed

Add task scheduling system to metagov-core #19

gigxz opened this issue Apr 8, 2021 · 5 comments · Fixed by #42
Assignees
Labels
enhancement New feature or request for metagov-core

Comments

@gigxz
Copy link
Collaborator

gigxz commented Apr 8, 2021

[updated]

Requirements

Add a scheduling system in metagov-core. Enable Plugin authors to access the scheduler for these 2 purposes:

  1. "Listener" plugins that send events to the Driver. When listening to a platform that doesn't have webhooks, plugin authors need to use polling to listen for changes. Metagov-core should expose some way for plugin authors to define a task that is invoked on a schedule.
  2. Async Governance Processes that listen for state changes (a vote being cast, a vote being closed, etc).

Possible tools to use

Celery, django-apscheduler

Things to consider:

  • Do what degree should the schedule intervals be configurable, and by whom?
    • If the Driver is evaluating the closing condition for a governance process, it needs to know the "latest" state of the process. The Driver should probably have the flexibility to set what the interval is, since it will affect the lag between the state change occurring and the Driver picking it up.
    • Consider that some gov processes last days or weeks. Could the polling interval be a function of the process closing_at date?
  • How do we not overload our server? The number of active scheduled tasks might be, at most: N communities * M listener plugins * P governance processes

[old]

The current "listener" interface requires that the external platform already has support for web hooks, and that it emits web hooks for all the events that the governance author cares about.

Read about implementing a Listener in a Plugin here: https://docs.metagov.org/en/latest/plugin_tutorial.html#listener

Problem: not all platforms have support for webhooks!

One example is NEAR: as a plugin author, I want to support "listening" to transactions occurring on the community's smart contract, so that the governance Driver can react to events. There is a public NEAR indexer for explorer that exposes a public API for querying transactions (or DataHub API which is similarly a public indexer). There are also services like BlockNative that let you monitor blockchain transactions using webhooks, but none of these support NEAR.

Alternative to webhooks: the alternative to webhooks is some kind of "pull" API where we fetch recent events from an API at regular intervals. This is what PolicyKit does using Celery tasks (with RabbitMQ broker). How can we make it easy for plugin authors to implement something like that? What technology should we use?

@gigxz
Copy link
Collaborator Author

gigxz commented Apr 8, 2021

One possibility is to use a celery schedule in Metagov Core, and allow Metagov Plugins to register task functions. Then the Plugin author doesn't have to worry about how the polling works.

  @Registry.plugin
  class MyPlugin(Plugin):

    @Registry.periodic_task
    def poll_events(self):
        """
        Function that gets called every minute/hour/day (however schedule is configured).
        Useful when you can't use a webhook.
        """
        events = requests.get(...) # fetch events from platform API 

        self.handle_event(event) # process event and send to driver

We need to be able to dynamically add and and remove scheduled tasks without restarting Django or Celery, as well as maybe dynamically changing the schedules (hourly/daily/etc) based on the plugin config.

@shaunagm
Copy link
Collaborator

shaunagm commented Apr 9, 2021

I think it would be fantastic for metagov to implement polling - it would make things much easier for plugin authors. I don't really know enough about this topic to make any recommendations, though.

@thelastjosh
Copy link
Member

thelastjosh commented Apr 9, 2021 via email

@shaunagm
Copy link
Collaborator

shaunagm commented Apr 9, 2021

Yes, checking, not surveying.

@gigxz gigxz changed the title No support for implementing a "listener" for a platform that does not emit webhooks Add task scheduling system to metagov-core, expose it to Plugins and GovernanceProcesses Apr 30, 2021
@gigxz gigxz added the enhancement New feature or request for metagov-core label Apr 30, 2021
@gigxz gigxz changed the title Add task scheduling system to metagov-core, expose it to Plugins and GovernanceProcesses Add task scheduling system to metagov-core Apr 30, 2021
@gigxz gigxz self-assigned this May 3, 2021
@gigxz gigxz closed this as completed in #42 May 6, 2021
@gigxz
Copy link
Collaborator Author

gigxz commented May 6, 2021

The instructions to Drivers for how to perform async governance processes was made simpler from this change: https://docs.metagov.org/en/latest/driver_tutorial.html#performing-governance-processes

The instructions for Metagov installation was made more complicated, because of the need to set up Celery: https://docs.metagov.org/en/latest/installation.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request for metagov-core
Projects
Development

Successfully merging a pull request may close this issue.

3 participants