automated terminal push
This commit is contained in:
114
consumer.py
114
consumer.py
@@ -1,46 +1,84 @@
|
|||||||
def write_to_file(filepath, content):
|
import stomp
|
||||||
"""Writes content to a file.
|
import time
|
||||||
|
import SullyGnomeRobot
|
||||||
|
import RestAPIClient
|
||||||
|
|
||||||
Args:
|
print("## ")
|
||||||
filepath: The path to the file.
|
print("## starting > JMS consumer (yankee-sully-channels-monthly)")
|
||||||
content: The string to write to the file.
|
print("## ")
|
||||||
Returns:
|
|
||||||
True on success, False on failure. Prints error messages.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
with open(filepath, 'w') as f: # 'w' mode overwrites, 'a' appends
|
|
||||||
f.write(content)
|
|
||||||
return True
|
|
||||||
except OSError as e:
|
|
||||||
print(f"Error writing to file {filepath}: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
print("running the consumer for effect!!!!")
|
class MyListener(stomp.ConnectionListener):
|
||||||
|
|
||||||
|
def on_message(headers, message):
|
||||||
|
|
||||||
# Example usage:
|
print("** new message! **")
|
||||||
filepath = "/tmp/file.dat" # Or any path you want
|
|
||||||
content = "yooo"
|
|
||||||
|
|
||||||
if write_to_file(filepath, content):
|
print("message / ", message)
|
||||||
print(f"Successfully wrote '{content}' to {filepath}")
|
|
||||||
else:
|
|
||||||
print("File write operation failed.")
|
|
||||||
|
|
||||||
|
print("messagebody / ", message.body)
|
||||||
|
|
||||||
# Example of appending:
|
print("checking the value does or doesnt exist in db")
|
||||||
def append_to_file(filepath, content):
|
|
||||||
"""Appends content to a file."""
|
|
||||||
try:
|
|
||||||
with open(filepath, 'a') as f: # 'a' mode appends
|
|
||||||
f.write(content)
|
|
||||||
return True
|
|
||||||
except OSError as e:
|
|
||||||
print(f"Error appending to file {filepath}: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Example usage of append:
|
alreadyExistsSuccess = RestAPIClient.searchURLSuccesses(message.body)
|
||||||
if append_to_file(filepath, "\nand more yooo"): # \n for a new line
|
|
||||||
print("Successfully appended to the file.")
|
print("alreadyExistsSuccess / ", alreadyExistsSuccess)
|
||||||
else:
|
|
||||||
print("File append operation failed.")
|
if alreadyExistsSuccess.lower().strip() == "true":
|
||||||
|
|
||||||
|
print("this record exists (successes). returning. doing nothing")
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
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("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)
|
||||||
|
|
||||||
|
def on_error(headers, message):
|
||||||
|
|
||||||
|
print('received an error "%s"' % message)
|
||||||
|
|
||||||
|
RestAPIClient.addDownloadFailure(message.body)
|
||||||
|
|
||||||
|
print("## ")
|
||||||
|
print("## starting > JMS consumer (yankee-sully-channels-monthly)")
|
||||||
|
print("## ")
|
||||||
|
|
||||||
|
conn = stomp.Connection([('osiris.yankee.embanet.online', 61613)])
|
||||||
|
|
||||||
|
conn.set_listener('', MyListener())
|
||||||
|
|
||||||
|
conn.connect('admin', 'password', wait=True)
|
||||||
|
|
||||||
|
conn.subscribe('/queue/yankee-sully-channels-monthly', id=1, ack='auto', headers={'activemq.prefetchSize': 10})
|
||||||
|
|
||||||
|
print("## ")
|
||||||
|
print("## notification > connected to JMS server (yankee-sully-channels-monthly)")
|
||||||
|
print("## ")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
conn.disconnect()
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ cp pizza.bash /tmp/pizza.bash
|
|||||||
chmod +x /tmp/pizza.bash
|
chmod +x /tmp/pizza.bash
|
||||||
|
|
||||||
|
|
||||||
echo "* * * * * yankee /bin/bash /tmp/pizza.bash >> /app/cron.log 2&>1" >> robotcron
|
echo "* * * * * yankee /bin/bash /tmp/pizza.bash >> /tmp/cron.log 2&>1" >> robotcron
|
||||||
|
|
||||||
echo
|
echo "* * * * * yankee /tmp/pizza.bash >> /var/log/cron.log 2>&1" >> robotcron
|
||||||
|
|
||||||
echo "printing crontab"
|
echo "printing crontab"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user