This is an automated email from the git hooks/post-receive script.
praiskup pushed a commit to branch master
in repository copr/copr.
The following commit(s) were added to refs/heads/master by this push:
new c6d8bc7 frontend: pagure-events fedora messaging support
c6d8bc7 is described below
commit c6d8bc7a1355aefffce43049f34f236e7437e45e
Author: Tomas Hrnciar <thrnciar(a)reedhat.com>
AuthorDate: Mon Sep 23 11:21:29 2019 +0200
frontend: pagure-events fedora messaging support
Adds support for listening pagure-events on fedora-messaging
and removes old zmq message bus.
It's necessary to update .toml file where log_config.handles.console
should look like this:
[log_config.handlers.console]
class = "logging.FileHandler"
formatter = "simple"
filename = "/var/log/copr-frontend/pagure-events.log"
[[bindings]]
queue = "00000000-0000-0000-0000-000000000003"
exchange = "amq.topic"
routing_keys = [
'io.pagure.prod.pagure.git.receive',
'io.pagure.prod.pagure.pull-request.new',
'io.pagure.prod.pagure.pull-request.rebased',
'io.pagure.prod.pagure.pull-request.updated',
'io.pagure.prod.pagure.pull-request.comment.added',
'org.fedoraproject.prod.pagure.git.receive',
'org.fedoraproject.prod.pagure.pull-request.new',
'org.fedoraproject.prod.pagure.pull-request.rebased',
'org.fedoraproject.prod.pagure.pull-request.updated',
'org.fedoraproject.prod.pagure.pull-request.comment.added',
'io.pagure.stg.pagure.git.receive',
'io.pagure.stg.pagure.pull-request.new',
'io.pagure.stg.pagure.pull-request.rebased',
'io.pagure.stg.pagure.pull-request.updated',
'io.pagure.stg.pagure.pull-request.comment.added'
]
Merges: #1025
---
frontend/copr-frontend.spec | 12 ++--
.../{run/pagure-events.py => pagure_events.py} | 81 ++++------------------
frontend/pagure-events.service | 11 ---
3 files changed, 18 insertions(+), 86 deletions(-)
diff --git a/frontend/copr-frontend.spec b/frontend/copr-frontend.spec
index b575f30..b490725 100644
--- a/frontend/copr-frontend.spec
+++ b/frontend/copr-frontend.spec
@@ -66,6 +66,7 @@ BuildRequires: graphviz
BuildRequires: python3-devel
%if %{with check}
+BuildRequires: fedora-messaging
BuildRequires: libmodulemd < 2
BuildRequires: libmodulemd >= 1.7.0
BuildRequires: python3-CommonMark
@@ -112,6 +113,7 @@ Requires: redis
Requires: %flavor_guard
Requires: (copr-selinux if selinux-policy-targeted)
+Requires: fedora-messaging
Requires: js-html5shiv
Requires: js-jquery1
Requires: js-respond
@@ -238,8 +240,6 @@ install -p -m 755 coprs_frontend/run/copr_dump_db.sh
%{buildroot}%{_libexecdir}
cp -a coprs_frontend/* %{buildroot}%{_datadir}/copr/coprs_frontend
sed -i "s/__RPM_BUILD_VERSION/%{version}-%{release}/"
%{buildroot}%{_datadir}/copr/coprs_frontend/coprs/templates/layout.html
-cp -a pagure-events.service %{buildroot}%{_unitdir}/
-
mv %{buildroot}%{_datadir}/copr/coprs_frontend/coprs.conf.example ./
mv %{buildroot}%{_datadir}/copr/coprs_frontend/config/* %{buildroot}%{_sysconfdir}/copr
rm %{buildroot}%{_datadir}/copr/coprs_frontend/CONTRIBUTION_GUIDELINES
@@ -287,16 +287,16 @@ usermod -L copr-fe
%post
/bin/systemctl condrestart httpd.service || :
-%systemd_post pagure-events.service
+%systemd_post fm-consumer(a)copr_messaging.service
%preun
-%systemd_preun pagure-events.service
+%systemd_preun fm-consumer(a)copr_messaging.service
%postun
/bin/systemctl condrestart httpd.service || :
-%systemd_postun_with_restart pagure-events.service
+%systemd_postun_with_restart fm-consumer(a)copr_messaging.service
%files
@@ -310,8 +310,6 @@ usermod -L copr-fe
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
-%{_unitdir}/pagure-events.service
-
%defattr(-, copr-fe, copr-fe, -)
%dir %{_sharedstatedir}/copr/data
%dir %{_sharedstatedir}/copr/data/openid_store
diff --git a/frontend/coprs_frontend/run/pagure-events.py
b/frontend/coprs_frontend/pagure_events.py
similarity index 85%
rename from frontend/coprs_frontend/run/pagure-events.py
rename to frontend/coprs_frontend/pagure_events.py
index a16346e..f88a00a 100755
--- a/frontend/coprs_frontend/run/pagure-events.py
+++ b/frontend/coprs_frontend/pagure_events.py
@@ -2,13 +2,13 @@
import json
import pprint
-import zmq
import sys
import os
import logging
import requests
import re
import munch
+import subprocess
sys.path.append(
os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
@@ -25,39 +25,18 @@ from urllib.parse import urlparse
SCM_SOURCE_TYPE = helpers.BuildSourceEnum("scm")
-logging.basicConfig(
- filename='{0}/pagure-events.log'.format(app.config.get('LOG_DIR')),
- format='[%(asctime)s][%(levelname)6s]: %(message)s',
- level=logging.DEBUG)
-
log = logging.getLogger(__name__)
-log.addHandler(logging.StreamHandler(sys.stdout))
-
if os.getenv('PAGURE_EVENTS_TESTONLY'):
ENDPOINT = 'tcp://stg.pagure.io:9940'
else:
ENDPOINT = 'tcp://hub.fedoraproject.org:9940'
+log.setLevel(logging.DEBUG)
log.info("ENDPOINT = {}".format(ENDPOINT))
-pagure_instances = {
- 'https://pagure.io/': 'io.pagure.prod.pagure',
- 'https://src.fedoraproject.org/': 'org.fedoraproject.prod.pagure',
- 'https://stg.pagure.io/': 'io.pagure.stg.pagure', # testing
only
-}
-
-topics = [
- 'git.receive',
- 'pull-request.new',
- 'pull-request.rebased',
- 'pull-request.updated',
- 'pull-request.comment.added',
-]
-
TOPICS = {}
-for url, fedmsg_prefix in pagure_instances.items():
- for topic in topics:
- TOPICS['{0}.{1}'.format(fedmsg_prefix, topic)] = url
+for topic, url in app.config["PAGURE_EVENTS"].items():
+ TOPICS['{0}'.format(topic)] = url
def get_repeatedly(url):
log.info("getting url {}".format(url))
@@ -219,46 +198,22 @@ def git_compare_urls(url1, url2):
return (o1.netloc == o2.netloc and o1.path == o2.path)
-def build_on_fedmsg_loop():
- log.debug("Setting up poller...")
- pp = pprint.PrettyPrinter(width=120)
-
- ctx = zmq.Context()
- s = ctx.socket(zmq.SUB)
-
- # detect server hang/restart (still a chance to loose ~45s events)
- # for more info see man tcp(7).
- s.setsockopt(zmq.TCP_KEEPALIVE, 1) # turn on keep-alive
- s.setsockopt(zmq.TCP_KEEPALIVE_IDLE, 30) # start when 30s inactive
- s.setsockopt(zmq.TCP_KEEPALIVE_INTVL, 5) # send keep-alive packet each 5s
- s.setsockopt(zmq.TCP_KEEPALIVE_CNT, 3) # restart after 3 fails
+class build_on_fedmsg_loop():
- s.connect(ENDPOINT)
-
- for topic in TOPICS:
- s.setsockopt_string(zmq.SUBSCRIBE, topic)
-
- poller = zmq.Poller()
- poller.register(s, zmq.POLLIN)
-
- while True:
- log.debug('Polling...')
- evts = poller.poll(10000)
- if not evts:
- continue
-
- log.debug('Receiving...')
- _, msg_bytes = s.recv_multipart()
- msg = msg_bytes.decode('utf-8')
+ def __call__(self, message):
+ pp = pprint.PrettyPrinter(width=120)
log.debug('Parsing...')
- data = json.loads(msg)
+ data = {
+ 'topic': message.topic,
+ 'msg': message.body
+ }
log.info('Got topic: {}'.format(data['topic']))
base_url = TOPICS.get(data['topic'])
if not base_url:
log.error('Unknown topic {} received. Continuing.')
- continue
+ return
if re.match(r'^.*.pull-request.(new|rebased|updated)$',
data['topic']):
event_info = event_info_from_pr(data, base_url)
@@ -271,7 +226,7 @@ def build_on_fedmsg_loop():
if not event_info:
log.info('Received event was discarded. Continuing.')
- continue
+ return
candidates = ScmPackage.get_candidates_for_rebuild(event_info.base_clone_url)
changed_files = set()
@@ -349,13 +304,3 @@ def build_on_fedmsg_loop():
db.session.commit()
else:
log.info('\t -> skipping.')
-
-
-if __name__ == '__main__':
- while True:
- try:
- build_on_fedmsg_loop()
- except KeyboardInterrupt:
- sys.exit(1)
- except:
- log.exception('Error in fedmsg loop. Restarting it.')
diff --git a/frontend/pagure-events.service b/frontend/pagure-events.service
deleted file mode 100644
index db3cc14..0000000
--- a/frontend/pagure-events.service
+++ /dev/null
@@ -1,11 +0,0 @@
-[Unit]
-Description=Run copr builds on pagure events
-
-[Service]
-User=copr-fe
-Group=copr-fe
-Environment="PYTHONPATH=/usr/share/copr/"
-ExecStart=/usr/bin/python3 /usr/share/copr/coprs_frontend/run/pagure-events.py
-
-[Install]
-WantedBy=multi-user.target
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.