Skip to content

Commit

Permalink
scheduler example added
Browse files Browse the repository at this point in the history
see #72952
  • Loading branch information
martinrode committed Jul 26, 2024
1 parent 6285d22 commit 0d589c5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
26 changes: 26 additions & 0 deletions manifest.master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ plugin:

base_url_prefix: "webfrontend"

# api extensions
extensions:
dump/empty:
exec:
Expand Down Expand Up @@ -194,6 +195,7 @@ extensions:
- type: "value"
value: "%info.json%"

# built-in callbacks which happen at certain points in the code flow of fylr server
callbacks:
export_transport:
copy_file:
Expand Down Expand Up @@ -399,6 +401,7 @@ callbacks:
- type: "value"
value: "%_exec.pluginDir%/server/db_pre_save+webhook/check.js"

# hook which is used when a collection upload happens, either via /api/eas?collection=ID or the hofolder
collection_upload:
filename_copy:
config:
Expand Down Expand Up @@ -456,6 +459,7 @@ collection_upload:
# - type: "value"
# value: "%_exec.pluginDir%/server/collection/filename_copy/config_check.js"

# base config extension. These parameters will be accessible via /api/config.
base_config:
- name: comment
parameters:
Expand Down Expand Up @@ -499,6 +503,28 @@ system_rights:
- name: preview-versions
type: preview-versions

# hook for the plugin scheduler
scheduler:
# name of this scheduler plugin
example: # "module"
callbacks:
run:
plugin_user:
reference: system:root
exec:
service: "python3"
commands:
- prog: "python3"
stdin:
type: body
stdout:
type: body
args:
- type: "value"
value: "%_exec.pluginDir%/server/scheduled/example.py"
- type: "value"
value: "%info.json%"

custom_types:
example:
mapping:
Expand Down
39 changes: 39 additions & 0 deletions server/scheduled/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json

import sys
import json


def respond():
response_json = json.dumps({
"status_code": 200,
"body": {
"log": ["log entry 1", "log entry 2"]
}
}, indent=4)
print(response_json)


def main():
# Check if at least one argument is provided
if len(sys.argv) < 2:
print("Usage: example.py <json_string>")
sys.exit(1)

# Read the first command-line argument
json_string = sys.argv[1]

try:
# Parse the JSON string
data = json.loads(json_string)
print("Parsed JSON data:", file=sys.stderr)
print(data, file=sys.stderr)
except json.JSONDecodeError as e:
print(f"Invalid JSON: {e}", file=sys.stderr)
sys.exit(1)

respond()

if __name__ == "__main__":
main()

0 comments on commit 0d589c5

Please sign in to comment.