forked from importers/git-importer
ruff format run
This commit is contained in:
parent
2d04136ca5
commit
479738d4b2
@ -3,39 +3,46 @@ import json
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import pika
|
import pika
|
||||||
import random
|
import random
|
||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
MY_TASKS_DIR = Path(__file__).parent / "tasks"
|
MY_TASKS_DIR = Path(__file__).parent / "tasks"
|
||||||
|
|
||||||
|
|
||||||
def listen_events():
|
def listen_events():
|
||||||
connection = pika.BlockingConnection(pika.URLParameters("amqps://opensuse:opensuse@rabbit.opensuse.org"))
|
connection = pika.BlockingConnection(
|
||||||
|
pika.URLParameters("amqps://opensuse:opensuse@rabbit.opensuse.org")
|
||||||
|
)
|
||||||
channel = connection.channel()
|
channel = connection.channel()
|
||||||
|
|
||||||
channel.exchange_declare(exchange='pubsub', exchange_type='topic', passive=True, durable=False)
|
channel.exchange_declare(
|
||||||
|
exchange="pubsub", exchange_type="topic", passive=True, durable=False
|
||||||
|
)
|
||||||
|
|
||||||
result = channel.queue_declare("", exclusive=True)
|
result = channel.queue_declare("", exclusive=True)
|
||||||
queue_name = result.method.queue
|
queue_name = result.method.queue
|
||||||
|
|
||||||
channel.queue_bind(exchange='pubsub',
|
channel.queue_bind(
|
||||||
queue=queue_name,routing_key='opensuse.obs.package.commit')
|
exchange="pubsub", queue=queue_name, routing_key="opensuse.obs.package.commit"
|
||||||
|
)
|
||||||
|
|
||||||
print(' [*] Waiting for logs. To exit press CTRL+C')
|
print(" [*] Waiting for logs. To exit press CTRL+C")
|
||||||
|
|
||||||
def callback(ch, method, properties, body):
|
def callback(ch, method, properties, body):
|
||||||
if method.routing_key not in ("opensuse.obs.package.commit",):
|
if method.routing_key not in ("opensuse.obs.package.commit",):
|
||||||
return
|
return
|
||||||
body = json.loads(body)
|
body = json.loads(body)
|
||||||
if 'project' in body and 'package' in body and body['project'] == 'openSUSE:Factory':
|
if (
|
||||||
if '/' in body['package']:
|
"project" in body
|
||||||
|
and "package" in body
|
||||||
|
and body["project"] == "openSUSE:Factory"
|
||||||
|
):
|
||||||
|
if "/" in body["package"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
(MY_TASKS_DIR / body['package']).touch()
|
(MY_TASKS_DIR / body["package"]).touch()
|
||||||
print(" [x] %r:%r" % (method.routing_key, body['package']))
|
print(" [x] %r:%r" % (method.routing_key, body["package"]))
|
||||||
|
|
||||||
channel.basic_consume(queue_name,
|
channel.basic_consume(queue_name, callback, auto_ack=True)
|
||||||
callback,
|
|
||||||
auto_ack=True)
|
|
||||||
|
|
||||||
channel.start_consuming()
|
channel.start_consuming()
|
||||||
|
|
||||||
@ -43,10 +50,10 @@ def listen_events():
|
|||||||
def main():
|
def main():
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
listen_events();
|
listen_events()
|
||||||
except pika.exceptions.ConnectionClosed:
|
except (pika.exceptions.ConnectionClosed, pika.exceptions.AMQPHeartbeatTimeout):
|
||||||
time.sleep(random.randint(10,100))
|
time.sleep(random.randint(10, 100))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user