Last active
December 5, 2017 08:39
-
-
Save nxnarbais/826a4e494e6c6e49ea895c3e29c54e9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <job | |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xmlns="urn:proactive:jobdescriptor:3.3" | |
| xsi:schemaLocation="urn:proactive:jobdescriptor:3.3 http://www.activeeon.com/public_content/schemas/proactive/jobdescriptor/3.3/schedulerjob.xsd" | |
| name="FolderMonitoring" | |
| priority="normal" | |
| cancelJobOnError="false"> | |
| <taskFlow> | |
| <task name="DirectoryMonitoring"> | |
| <description> | |
| <![CDATA[ Give the changes in a directory every minute ]]> | |
| </description> | |
| <scriptExecutable> | |
| <script> | |
| <code language="python"> | |
| <![CDATA[ | |
| #Will monitor the given directory (must be availible from the node) and return changes as a result. | |
| #The dataspace is available from all nodes. Otherwise, a selsction script must be used. | |
| MonitoredDir = userspace # Monitor the userspace. | |
| # MonitoredDir = "/home" #Check for permissions to access directory | |
| #Nothing is supposed to be changed after this point. | |
| import os | |
| import sys | |
| from os.path import isfile, join | |
| #Create a list of all files in the directory. | |
| listFiles = os.listdir(MonitoredDir) | |
| listFiles = [f for f in listFiles if isfile(join(MonitoredDir, f))] | |
| result = [] | |
| #The following will loop on all the files and compare their content to the content in the last loop. If first loop, they will be marked as created. | |
| for filename in listFiles: | |
| print filename | |
| with open( (MonitoredDir + '/' + filename), 'rb') as f: | |
| content = f.read() | |
| if variables.containsKey(filename): | |
| if (variables[filename] == content): | |
| #result.append(('UNCHANGED/' + filename).encode('utf-8')) | |
| variables['listFiles'].remove(filename) | |
| else: | |
| variables[filename] = content | |
| result.append (('UPDATED/' + filename).encode('utf-8')) | |
| variables['listFiles'].remove(filename) | |
| else: | |
| variables[filename] = content | |
| result.append (('CREATED/' + filename).encode('utf-8')) | |
| #If not first itteration will look for deleted files and update the file list. | |
| if variables.containsKey('listFiles'): | |
| for filename in variables['listFiles']: | |
| result.append(('DELETED/' + filename).encode('utf-8')) | |
| variables.remove(filename) | |
| variables['listFiles'] = listFiles | |
| #No results available in first loop. | |
| if (variables["PA_TASK_ITERATION"] == 0): | |
| result = [] | |
| ]]> | |
| </code> | |
| </script> | |
| </scriptExecutable> | |
| <controlFlow block="start"></controlFlow> | |
| </task> | |
| <task name="End"> | |
| <description> | |
| <![CDATA[ Loop every minute ]]> | |
| </description> | |
| <depends> | |
| <task ref="Action"/> | |
| </depends> | |
| <scriptExecutable> | |
| <script> | |
| <code language="javascript"> | |
| <![CDATA[ | |
| // End of the loop | |
| ]]> | |
| </code> | |
| </script> | |
| </scriptExecutable> | |
| <controlFlow block="end"> | |
| <loop target="DirectoryMonitoring"> | |
| <script> | |
| <code language="javascript"> | |
| <![CDATA[ | |
| // You can use a Cron Expression here | |
| // examples | |
| http://www.sauronsoftware.it/projects/cron4j/manual.php#p02 | |
| loop = '* * * * *'; | |
| ]]> | |
| </code> | |
| </script> | |
| </loop> | |
| </controlFlow> | |
| </task> | |
| <task name="Action"> | |
| <description> | |
| <![CDATA[ A set of actions using the changes in the directory ]]> | |
| </description> | |
| <depends> | |
| <task ref="DirectoryMonitoring"/> | |
| </depends> | |
| <scriptExecutable> | |
| <script> | |
| <code language="javascript"> | |
| <![CDATA[ | |
| // This shows how to retreive and use the result of the previous task. | |
| // You can replace this task by any workflow. | |
| //print(results) | |
| for (x in results[0].value()){ | |
| State = (results[0].value()[x].split('/')) | |
| Change = State[0] | |
| Name = State[1] | |
| print (Name + ' has been ' + Change) | |
| } | |
| ]]> | |
| </code> | |
| </script> | |
| </scriptExecutable> | |
| </task> | |
| </taskFlow> | |
| </job> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment