✨ Toy workflow addition
This commit is contained in:
21
example_workflow/job_output/job_FQQUQMTGtqUw/job.sh
Executable file
21
example_workflow/job_output/job_FQQUQMTGtqUw/job.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Get job params
|
||||
given_hash=$(grep 'file_hash: *' $(dirname $0)/job.yml | tail -n1 | cut -c 14-)
|
||||
event_path=$(grep 'event_path: *' $(dirname $0)/job.yml | tail -n1 | cut -c 15-)
|
||||
|
||||
echo event_path: $event_path
|
||||
echo given_hash: $given_hash
|
||||
|
||||
# Check hash of input file to avoid race conditions
|
||||
actual_hash=$(sha256sum $event_path | cut -c -64)
|
||||
echo actual_hash: $actual_hash
|
||||
if [ "$given_hash" != "$actual_hash" ]; then
|
||||
echo Job was skipped as triggering file has been modified since scheduling
|
||||
exit 134
|
||||
fi
|
||||
|
||||
# Call actual job script
|
||||
python3 job_queue/job_FQQUQMTGtqUw/recipe.py >>job_queue/job_FQQUQMTGtqUw/output.log 2>&1
|
||||
|
||||
exit $?
|
38
example_workflow/job_output/job_FQQUQMTGtqUw/job.yml
Normal file
38
example_workflow/job_output/job_FQQUQMTGtqUw/job.yml
Normal file
@ -0,0 +1,38 @@
|
||||
create: 2023-06-07 11:54:48.117191
|
||||
end: 2023-06-07 11:54:53.231092
|
||||
error: Job execution returned non-zero.
|
||||
event:
|
||||
event_path: /tmp/tmp3q4q94ee
|
||||
event_rule: !!python/object:meow_base.core.rule.Rule
|
||||
name: rule_xjGHQxaaray
|
||||
pattern: !!python/object:meow_base.patterns.network_event_pattern.NetworkEventPattern
|
||||
name: echo_pattern
|
||||
outputs: {}
|
||||
parameters: {}
|
||||
recipe: echo_recipe
|
||||
sweep: {}
|
||||
triggering_port: 8080
|
||||
recipe: !!python/object:meow_base.recipes.python_recipe.PythonRecipe
|
||||
name: echo_recipe
|
||||
parameters: {}
|
||||
recipe:
|
||||
- path = {PATH}
|
||||
- print(path)
|
||||
requirements: &id001 {}
|
||||
event_time: 1686131685.3071685
|
||||
event_type: network
|
||||
file_hash: f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2
|
||||
monitor_base: ''
|
||||
triggering_port: 8080
|
||||
id: job_FQQUQMTGtqUw
|
||||
job_type: python
|
||||
parameters: {}
|
||||
pattern: echo_pattern
|
||||
recipe: echo_recipe
|
||||
requirements: *id001
|
||||
rule: rule_xjGHQxaaray
|
||||
start: 2023-06-07 11:54:53.168581
|
||||
status: failed
|
||||
tmp recipe command: python3 job_queue/job_FQQUQMTGtqUw/recipe.py >>job_queue/job_FQQUQMTGtqUw/output.log
|
||||
2>&1
|
||||
tmp script command: ./job.sh
|
2
example_workflow/job_output/job_FQQUQMTGtqUw/recipe.py
Executable file
2
example_workflow/job_output/job_FQQUQMTGtqUw/recipe.py
Executable file
@ -0,0 +1,2 @@
|
||||
path = {PATH}
|
||||
print(path)
|
53
example_workflow/network_workflow.py
Normal file
53
example_workflow/network_workflow.py
Normal file
@ -0,0 +1,53 @@
|
||||
from time import sleep
|
||||
|
||||
from meow_base.core.runner import MeowRunner
|
||||
from meow_base.patterns.network_event_pattern import NetworkMonitor, NetworkEventPattern
|
||||
from meow_base.recipes.python_recipe import PythonRecipe, PythonHandler
|
||||
from meow_base.conductors.local_python_conductor import LocalPythonConductor
|
||||
|
||||
PORTS = [8080,8181]
|
||||
|
||||
def main():
|
||||
runners = []
|
||||
for i, port in enumerate(PORTS):
|
||||
other_port = PORTS[(i+1)%2]
|
||||
|
||||
# Gets the script ready
|
||||
script = [
|
||||
"import socket",
|
||||
"sender = socket.socket(socket.AF_INET, socket.SOCK_STREAM)",
|
||||
f"sender.connect(('127.0.0.1', {other_port}))",
|
||||
"sender.sendall(b'test')",
|
||||
"sender.close()"
|
||||
]
|
||||
|
||||
# Initialize the network monitor
|
||||
patterns = {
|
||||
"echo_pattern":NetworkEventPattern(
|
||||
"echo_pattern",
|
||||
port,
|
||||
"echo_recipe"
|
||||
)
|
||||
}
|
||||
recipes = {"echo_recipe":PythonRecipe("echo_recipe", script)}
|
||||
monitors = [NetworkMonitor(patterns, recipes)]
|
||||
|
||||
|
||||
# Initialize the handler and conductor
|
||||
handlers = [PythonHandler()]
|
||||
conductors = [LocalPythonConductor()]
|
||||
|
||||
# Start the runner
|
||||
runner = MeowRunner(monitors, handlers, conductors)
|
||||
|
||||
runner.start()
|
||||
runners.append(runner)
|
||||
|
||||
sleep(120)
|
||||
|
||||
for runner in runners:
|
||||
runner.stop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user