simplify hooks (wip)
This commit is contained in:
parent
0913b8eab9
commit
c78dc87575
15 changed files with 151 additions and 42 deletions
|
|
@ -84,15 +84,15 @@ start_hook_daemon(){
|
||||||
$0 infinite 86400 hook daily &
|
$0 infinite 86400 hook daily &
|
||||||
$0 infinite 3600 hook hourly &
|
$0 infinite 3600 hook hourly &
|
||||||
# trigger hooks when files change in /mnt
|
# trigger hooks when files change in /mnt
|
||||||
find /mnt -type d -mindepth 1 -maxdepth 1 | while read dir; do
|
#find /mnt -type d -mindepth 1 -maxdepth 1 | while read dir; do
|
||||||
echocolor "[$APPNAME]" "listening to inotify events in $dir"
|
# echocolor "[$APPNAME]" "listening to inotify events in $dir"
|
||||||
# scan for '/mnt/experiences/creatorname/#234/ MODIFY foo.glb' e.g.
|
# # scan for '/mnt/experiences/creatorname/#234/ MODIFY foo.glb' e.g.
|
||||||
# scan for '/mnt/experiences/creatorname/#234/ MOVED_TO foo.glb' e.g.
|
# # scan for '/mnt/experiences/creatorname/#234/ MOVED_TO foo.glb' e.g.
|
||||||
inotifywait -r -m $dir | awk '/.*/ { print $0 }; $2 ~ /(CREATE|MODIFY|MOVED_TO|DELETE)/ && $3 ~ /datapackage/ { system("'$0' hook datapackage_"$2" "$1""$3) }' &
|
# inotifywait -r -m $dir | awk '/.*/ { print $0 }; $2 ~ /(CREATE|MODIFY|MOVED_TO|DELETE)/ && $3 ~ /datapackage/ { system("'$0' hook datapackage_"$2" "$1""$3) }' &
|
||||||
done
|
#done
|
||||||
|
|
||||||
# force-trigger processing hooks in /mnt
|
## force-trigger processing hooks in /mnt
|
||||||
find /mnt | grep datapackage | xargs -n1 $0 hook inotify_MODIFY
|
#find /mnt | grep datapackage | xargs -n1 $0 hook inotify_MODIFY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
3
manyfold/root/hook.d/daily/cleanup_taskspooler.sh
Normal file
3
manyfold/root/hook.d/daily/cleanup_taskspooler.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# remove succesful tasks
|
||||||
|
ts | awk '$4 == 0 { print $1 }' | xargs -n1 ts -r
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
../hourly/placeholder.sh
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
test -f "$1".zip && rm "$1".zip
|
|
||||||
echo "[cleanup_package.sh] deleting $dir.zip"
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do
|
|
||||||
dir=$(dirname $1)
|
|
||||||
cd "$dir"
|
|
||||||
echo "[v] reset log.txt"
|
|
||||||
date > log.txt
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do
|
|
||||||
dir=$(dirname $1)
|
|
||||||
cd "$dir"
|
|
||||||
echo "[v] scan (new) files of model"
|
|
||||||
id="$(basename "$dir" | sed 's/\#//g')"
|
|
||||||
echo "Model.find(id).add_new_files_later()" | /usr/src/app/bin/rails console
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
datapackage_MODIFY
|
|
||||||
4
manyfold/root/hook.d/experience_updated/10-reset-log.sh
Executable file
4
manyfold/root/hook.d/experience_updated/10-reset-log.sh
Executable file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
cd "$1"
|
||||||
|
echo "[v] reset log.txt"
|
||||||
|
date > log.txt
|
||||||
5
manyfold/root/hook.d/experience_updated/1000-scan-dir.sh
Executable file
5
manyfold/root/hook.d/experience_updated/1000-scan-dir.sh
Executable file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
cd "$1"
|
||||||
|
echo "[v] scan (new) files of model"
|
||||||
|
id="$(basename "$dir" | sed 's/\#//g')"
|
||||||
|
#echo "Model.find(id).add_new_files_later()" | /usr/src/app/bin/rails console
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do
|
dir="$1"
|
||||||
dir=$(dirname $1)
|
|
||||||
cd "$dir"
|
cd "$dir"
|
||||||
echo "[package_experience.sh] zipping $dir.zip"
|
echo "[package_experience.sh] zipping $dir.zip"
|
||||||
zip -r "$dir".zip $dir/*
|
zip -r "$dir".zip $dir/*
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do
|
dir="$1"
|
||||||
dir=$(dirname $1)
|
|
||||||
cd "$dir"
|
cd "$dir"
|
||||||
echo "[package_experience.sh] zipping $dir.zip"
|
echo "[package_experience.sh] zipping $dir.zip"
|
||||||
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do
|
dir="$1"
|
||||||
dir=$(dirname $1)
|
|
||||||
cd "$dir"
|
cd "$dir"
|
||||||
echo "[package_janusxr.sh] packing janusxr.html"
|
echo "[package_janusxr.sh] packing janusxr.html"
|
||||||
|
|
||||||
|
|
@ -5,11 +5,12 @@ require_relative './../../xrforge.rb'
|
||||||
|
|
||||||
# Check if a filename is provided
|
# Check if a filename is provided
|
||||||
if ARGV.length != 1
|
if ARGV.length != 1
|
||||||
puts "Usage: #{$0} <path/to/datapackage.json>"
|
puts "Usage: #{$0} <path/to/experience>"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
filename = ARGV[0]
|
dir = ARGV[0]
|
||||||
|
filename = "#{dir}/datapackage.json"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# Read and parse the JSON file
|
# Read and parse the JSON file
|
||||||
|
|
@ -6,21 +6,33 @@ Rails.application.config.to_prepare do
|
||||||
|
|
||||||
# extend by adding listeners
|
# extend by adding listeners
|
||||||
class Model
|
class Model
|
||||||
# The 'after_save' macro is now run within the context of the existing Model class.
|
|
||||||
|
attr_accessor :last_action_execution_time
|
||||||
|
|
||||||
|
# The macro is now run within the context of the existing Model class.
|
||||||
after_commit :run_cli_hooks
|
after_commit :run_cli_hooks
|
||||||
|
|
||||||
# Define the new method to be executed on save.
|
# Define the new method to be executed on save.
|
||||||
def run_cli_hooks
|
def run_cli_hooks
|
||||||
# Your custom logic to execute after Model.save or Model.update! goes here.
|
# Your custom logic to execute after Model.save or Model.update! goes here.
|
||||||
|
|
||||||
# 📝 Example Logic:
|
now = Time.current
|
||||||
puts "\n-------- MODEL --------- #{self.id}\n\n"
|
rate_limit_seconds = 2.0
|
||||||
pp self
|
last_run_time = @last_action_execution_time
|
||||||
puts "\n\n"
|
|
||||||
|
|
||||||
command = "pwd"
|
if self.path.match('#')
|
||||||
system(command)
|
if last_run_time.nil? || (now - last_run_time) > rate_limit_seconds
|
||||||
|
self.last_action_execution_time = now
|
||||||
|
|
||||||
|
# 📝 Example Logic:
|
||||||
|
puts "\n-------- MODEL --------- #{self.id} #{self.path}\n\n"
|
||||||
|
pp self
|
||||||
|
puts "\n\n"
|
||||||
|
|
||||||
|
command = "TS_SLOTS=5 ts /manyfold/cli/manyfold.sh hook experience_updated #{self.library.path}/#{self.path} &"
|
||||||
|
system(command)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
105
manyfold/usr/src/app/config/locales/models/en.yml
Normal file
105
manyfold/usr/src/app/config/locales/models/en.yml
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
---
|
||||||
|
en:
|
||||||
|
models:
|
||||||
|
bulk_edit:
|
||||||
|
description: 'Select models to change:'
|
||||||
|
form_subtitle: 'Select changes to make:'
|
||||||
|
merge: Merge selected models
|
||||||
|
needs_organizing: Needs organizing
|
||||||
|
remove_tags: Remove tags
|
||||||
|
select: Select model '%{name}'
|
||||||
|
select_all: Select all models
|
||||||
|
submit: Update Selected Experiences
|
||||||
|
title: Bulk Edit Experiences
|
||||||
|
update_all: Update All %{count} Experiences
|
||||||
|
bulk_fields:
|
||||||
|
add_tags: Add tags
|
||||||
|
bulk_update:
|
||||||
|
success: Experiences updated successfully.
|
||||||
|
configure_merge:
|
||||||
|
common_root:
|
||||||
|
description: The models will be combined into a single one in the shared root folder
|
||||||
|
title: New model in common root folder
|
||||||
|
description: Select one of the models to merge the others into, or create a new one.
|
||||||
|
heading: Merge models
|
||||||
|
new_model:
|
||||||
|
description: A new model will be created from the combined data, and automatically organised on disk.
|
||||||
|
title: New model
|
||||||
|
create:
|
||||||
|
success: File(s) uploaded successfully.
|
||||||
|
destroy:
|
||||||
|
confirm: This will delete associated files if they exist on disk. Are you sure you want to continue?
|
||||||
|
success: Model deleted!
|
||||||
|
file:
|
||||||
|
delete: Delete file
|
||||||
|
edit: Edit file
|
||||||
|
open_button:
|
||||||
|
label: View details for %{name}
|
||||||
|
text: Open
|
||||||
|
presupported: Presupported Version
|
||||||
|
set_as_preview: Set as preview
|
||||||
|
form:
|
||||||
|
notes:
|
||||||
|
help_html: You can use <a href="https://www.markdownguide.org/cheat-sheet/" target="markdown">Markdown</a>.
|
||||||
|
preview_file:
|
||||||
|
help: The file displayed as a model preview in library pages
|
||||||
|
tags: Tags
|
||||||
|
general:
|
||||||
|
edit: Edit Model
|
||||||
|
image_carousel:
|
||||||
|
next: Next
|
||||||
|
play_pause: Play or pause images
|
||||||
|
previous: Previous
|
||||||
|
select_slide: Choose image to display
|
||||||
|
slide_label: "%{name} (%{index} of %{count})"
|
||||||
|
list:
|
||||||
|
bulk_edit: Edit All Experiences
|
||||||
|
no_results_html: Sorry, we couldn't find anything to show you! Try changing your filters or search terms, or uploading some models.
|
||||||
|
no_results_signed_out_html: Sorry, we couldn't find anything to show you! There might be more to see if you <a href="%{link}">sign in</a>.
|
||||||
|
skip_models: Skip model list
|
||||||
|
merge:
|
||||||
|
success: Experiences merged successfully.
|
||||||
|
new:
|
||||||
|
description: Add new models by uploading files! If you upload a compressed archive, it will be extracted and become a single model containing all the files. If you upload individual files, they will each become a separate model.
|
||||||
|
files:
|
||||||
|
label: Select Files
|
||||||
|
free_space: "(%{available} free)"
|
||||||
|
library:
|
||||||
|
help: The library to upload to.
|
||||||
|
submit: Create models
|
||||||
|
title: Upload
|
||||||
|
problem:
|
||||||
|
merge_all: Merge all
|
||||||
|
scan:
|
||||||
|
success: Model scan started
|
||||||
|
show:
|
||||||
|
download_preparing: Download is being prepared, please wait.
|
||||||
|
download_requested: Download requested and will be ready soon, please wait.
|
||||||
|
files: Files
|
||||||
|
files_card:
|
||||||
|
bulk_edit: Edit all files
|
||||||
|
heading: Files
|
||||||
|
followers: Followers
|
||||||
|
license: License
|
||||||
|
merge:
|
||||||
|
heading: Merge
|
||||||
|
warning: Merging moves all files from this model to the target, and removes this model. File metadata is preserved, but any model metadata will be lost!
|
||||||
|
with: Merge with
|
||||||
|
model_details: Model Details
|
||||||
|
organize:
|
||||||
|
button_text: Organize files
|
||||||
|
confirm:
|
||||||
|
are_you_sure: Are you sure you want to do this?
|
||||||
|
'no': No, cancel
|
||||||
|
summary_html: The folder and files that make up this model will be moved from:<br> <code>%{from}</code><br> to<br> <code>%{to}</code>
|
||||||
|
'yes': Yes, move the files
|
||||||
|
path: Path
|
||||||
|
preview: This is just a preview of the complete model, which contains %{count} more files. Contact the model owner to get full access.
|
||||||
|
rescan: Rescan files
|
||||||
|
search: Search the Internet for models with this name
|
||||||
|
submit: Upload Files
|
||||||
|
tags: Tags
|
||||||
|
upload_card:
|
||||||
|
heading: Upload
|
||||||
|
update:
|
||||||
|
success: Model details saved.
|
||||||
Loading…
Add table
Reference in a new issue