128 lines
2.8 KiB
Python
128 lines
2.8 KiB
Python
import stomp
|
|
import time
|
|
import SullyGnomeRobot
|
|
import RestAPIClient
|
|
|
|
### start variables ###
|
|
|
|
jmsQueue="asian-tester"
|
|
|
|
host = '38.107.226.34'
|
|
|
|
port = 61613
|
|
|
|
|
|
username = 'admin'
|
|
password = 'password'
|
|
|
|
|
|
### end variables ###
|
|
|
|
print("## ")
|
|
print(f"## starting > JMS consumer app!")
|
|
print("## ")
|
|
|
|
def writeSullyURLToJMS():
|
|
|
|
channel="https://sullygnome.com/channel/yaritaiji/2024october/games"
|
|
|
|
print(f"launch -> jms writer -> channel-> {channel}")
|
|
|
|
conn = stomp.Connection([('osiris.yankee.embanet.online', 61613)])
|
|
|
|
conn.connect('admin', 'password', wait=True)
|
|
|
|
try:
|
|
|
|
conn.send(body=channel.strip(), destination=f'/queue/{jmsQueue}')
|
|
|
|
finally:
|
|
|
|
conn.disconnect()
|
|
|
|
class MyListener(stomp.ConnectionListener):
|
|
|
|
def on_message(headers, message):
|
|
|
|
## print("** new message! **")
|
|
|
|
## print("message / ", message)
|
|
|
|
print("JMS url -> ", message.body)
|
|
|
|
## print("checking the value does or doesnt exist in db")
|
|
|
|
alreadyExistsSuccess = RestAPIClient.searchURLSuccesses(message.body)
|
|
|
|
## print("alreadyExistsSuccess / ", alreadyExistsSuccess)
|
|
|
|
if alreadyExistsSuccess.lower().strip() == "true":
|
|
|
|
## print("this record exists (successes). returning. doing nothing")
|
|
|
|
## return
|
|
|
|
print ("skipped!!")
|
|
|
|
## print("didn't exist in success. check in errors now.")
|
|
|
|
alreadyExistsFailure = RestAPIClient.searchURLFailures(message.body)
|
|
|
|
## print("alreadyExistsFailure / ", alreadyExistsFailure)
|
|
|
|
if alreadyExistsFailure.lower().strip() == "true":
|
|
|
|
## print("this record exists (failures). returning. doing nothing")
|
|
|
|
##return
|
|
|
|
print ("skipped!!")
|
|
|
|
print("didn't exist in success or errors. will process now")
|
|
|
|
try:
|
|
|
|
SullyGnomeRobot.download(message.body)
|
|
|
|
except Exception as e:
|
|
|
|
print(f"exception / something went wrong when the sully gnome robot was downloading: {e}")
|
|
|
|
RestAPIClient.addDownloadFailure(message.body, e)
|
|
|
|
def on_error(headers, message):
|
|
|
|
print('received an error "%s"' % message)
|
|
|
|
RestAPIClient.addDownloadFailure(message.body, "error from onmessage (consumer.py)")
|
|
|
|
print("## ")
|
|
print(f"## starting > JMS consumer ([{jmsQueue}]")
|
|
print("## ")
|
|
|
|
writeSullyURLToJMS()
|
|
connection_details = [(host, port)]
|
|
|
|
conn = stomp.Connection(connection_details)
|
|
|
|
conn.set_listener('', MyListener())
|
|
|
|
conn.connect(username, password, wait=True)
|
|
|
|
conn.subscribe(f'/queue/{jmsQueue}', id=1, ack='auto', headers={'activemq.prefetchSize': 10})
|
|
|
|
print(f"Subscribed to queue: {jmsQueue}")
|
|
|
|
print("## ")
|
|
print(f"## notification > connected to JMS server [{jmsQueue}] (upgrade)")
|
|
print("## ")
|
|
|
|
while True:
|
|
|
|
pass
|
|
|
|
time.sleep(1)
|
|
|
|
conn.disconnect()
|
|
|