Scripts/commit_and_push.py

24 lines
950 B
Python

def handleMessage(payload):
import time
script_path = '/usr/local/bin/ignition/data/factorystack/scripts/ignition-save.sh'
project = payload['project']
logger = system.util.getLogger("FactoryStack")
logger.info("'Commit and Push' request received from project '{}'.".format(project))
try:
actor = payload['actor']
resources = payload['resources']
added = ['/'.join([project, resource['path']]) for resource in resources['added']]
modified = ['/'.join([project, resource['path']]) for resource in resources['modified']]
removed = ['/'.join([project, resource['path']]) for resource in resources['removed']]
time.sleep(5) # following best practices guide from Inductive Automation
system.util.execute([script_path] + [actor] + added + modified + removed)
logger.info("'Commit and Push' operation completed.")
except:
logger.error("Error occurred during 'Commit and Push' operation. Please contact 4IR Support.")