metakgp / metakgp-wiki

Dockerized source for the metakgp wiki.
https://wiki.metakgp.org
GNU General Public License v3.0
23 stars 20 forks source link

Added batman #7

Closed nishnik closed 7 years ago

nishnik commented 7 years ago

ping @amrav I am using https://www.mediawiki.org/wiki/Extension:SlackNotifications

Before deploying one has to enter the webhook only, shared in slack.

DefCon-007 commented 7 years ago

@nishnik How about we add webhook in .env file and get it from there in place of hard coding it in LocalSettings.php

amrav commented 7 years ago

Hey @nishnik, thanks for the PR! Unfortunately this extension can't be used as-is, because the post to Slack's API happens synchronously on the request path, which can be quite slow (of the order of seconds), which drives up the page save latency. Also, if the post fails, the page save appears to fail (but actually succeeds, if I remember correctly) which isn't great.

The solution we used previously was to take the post to Slack out of the request path, by using a redis-backed job queue (example). I'd be happy to help you set that up, or discuss any other solution you can think of.

nishnik commented 7 years ago

That makes sense.

Is there some way to check a table update in MySQL and create a trigger for this (I couldn't find any), though a way I can think of is to check the mysql database every minute (or 5 minutes) for an update (via a cron job) and post to slack (if there is an update). This way we are independent of the wiki making even one request for any notification.

Otherwise we can go with the redis thing.

We should keep our discussions on github only for future references.

amrav commented 7 years ago

MySQL does support triggers, although that might be too powerful/low-level for our use case. We'd need a separate service listening to the trigger and processing updates anyway.

Your point about the wiki making requests on the write path is correct, but Redis is designed to be very fast for exactly these kinds of use cases. I'd expect it to take <0.1ms to respond. Redis also has the advantage of being easy to reason about and use if we want to add more asynchronous side effects to wiki actions in the future.

If we go the way of implementing a job queue on redis, then the steps would look like:

  1. Set up a redis container and link it to the php container (30 minutes)
  2. Fork the Slack extension, and modify it to post updates to the redis job queue (1-2 hours)
  3. Add a "jobs" container for running misc jobs like Slack updates (10 minutes)
  4. Add a slack update service to the jobs container, that reads from the redis job queue and posts to Slack (1 hour)
  5. Make the slack update service restart automatically if it goes down, using something like upstart. (30 mins)

What do you think? Also, agree with keeping discussions on Github.

nishnik commented 7 years ago

I was trying to work on it. Got a redis container working: Initialy I was trying to install from scratch as in DigitalOcean guides, but then this worked:

FROM redis:alpine
COPY redis.conf /usr/local/etc/redis/redis.conf

I am stuck in the second part, could you give me some hint on how to do it. (Modifying the slack extension)

After which I think I would create one more container, install python in it and use the batman to post messages ?

amrav commented 7 years ago

Could you push your changes on your branch, so I can take a look?

Here's a dump of the code we were previously using, that will help you along. I think we were using the phpredis library, which is installable from pecl. Make sure to read it carefully and understand what it's doing – it could definitely use some cleanup.

I think we want to copy the source of this extension into our repo, and maintain it ourselves. This will save us from having to write the extension from scratch, which involves a lot of boilerplate.

Yes, the third container can be a "jobs" container, where we put any miscellaneous jobs.

amrav commented 7 years ago

@nishnik ping on this

amrav commented 7 years ago

Done in #22, thanks!