Skip to content

Commit

Permalink
WIP: add cronjob and shell script
Browse files Browse the repository at this point in the history
  • Loading branch information
SteKrause committed Aug 25, 2023
1 parent 1c1e734 commit c794f0d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: batch/v1
kind: CronJob
metadata:
namespace: {{ NAMESPACE }}
labels:
app: api-library-management-cronjob
name: api-library-management-cronjob
spec:
schedule: "{{ SERVER_LIBRARY_MANAGEMENT_CRONJOB|default("0 3 * * 3,6", true) }}"
concurrencyPolicy: Forbid
jobTemplate:
spec:
activeDeadlineSeconds: {{ SERVER_LIBRARY_MANAGEMENT_CRONJOB_TIMEOUT|default("39600", true) }}
template:
spec:
containers:
- name: api-library-management-cronjob
image: {{ SCHULCLOUD_SERVER_IMAGE }}:{{ SCHULCLOUD_SERVER_IMAGE_TAG }}
envFrom:
- configMapRef:
name: api-configmap
- secretRef:
name: api-secret
command: ['/schulcloud-server/scripts/ldapSync.sh']
resources:
limits:
cpu: {{ API_CPU_LIMITS|default("2000m", true) }}
memory: {{ API_MEMORY_LIMITS|default("2Gi", true) }}
requests:
cpu: {{ API_CPU_REQUESTS|default("100m", true) }}
memory: {{ API_MEMORY_REQUESTS|default("150Mi", true) }}
restartPolicy: OnFailure
27 changes: 27 additions & 0 deletions scripts/libraryManagement.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
set -eu

default_time_out=39600
value_time_out=${SERVER_LIBRARY_MANAGEMENT_CRONJOB_TIMEOUT:-$default_time_out}

default_api_key="example"
value_api_key="${SYNC_API_KEY:-$default_api_key}"

# Start server in the background and redirect logs to file
nohup npm run nest:start > server.log 2>&1 &

# Show logs and wait for server to start up
echo "Server logs:"
tail -f server.log &

echo "Wait for server to start..."
until curl -s -w --retry 10 --retry-max-time 120 --retry-connrefused --retry-delay 10 http://localhost:3030/serverversion >/dev/null 2>&1; do
sleep 1
echo "asleep"
done

# Start sync
echo "Starting"
curl --max-time $value_time_out -H "X-API-Key: $value_api_key" "http://localhost:3030/api/v1/sync?target=ldap&forceFullSync=true" | python3 -m json.tool

# Process stops automatically and deletes logs with end of job pod

0 comments on commit c794f0d

Please sign in to comment.