-
-
Notifications
You must be signed in to change notification settings - Fork 23
Dataset cache purge cronjob #1211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
cbf5b54
c7f438f
4c7d8ae
946cca3
628488c
97a7d55
4d609d9
25d022e
30ccd81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||
| apiVersion: batch/v1 | ||||||||||
ponyisi marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| kind: CronJob | ||||||||||
| metadata: | ||||||||||
| name: {{ .Release.Name }}-dataset-lifecycle-job | ||||||||||
| spec: | ||||||||||
| schedule: {{ .Values.datasetLifecycle.schedule | default "0 * * * *" | quote }} | ||||||||||
| concurrencyPolicy: "Forbid" | ||||||||||
| jobTemplate: | ||||||||||
| spec: | ||||||||||
| template: | ||||||||||
| metadata: | ||||||||||
| labels: | ||||||||||
| app: {{ .Release.Name }}-dataset-lifecycle-job | ||||||||||
| spec: | ||||||||||
| containers: | ||||||||||
| - name: {{ .Release.Name }}-dataset-lifecycle-job | ||||||||||
| image: {{ .Values.datasetLifecycle.image }}:{{ .Values.datasetLifecycle.tag }} | ||||||||||
| imagePullPolicy: {{ .Values.datasetLifecycle.pullPolicy }} | ||||||||||
| env: | ||||||||||
| - name: LIFETIME | ||||||||||
| value: {{ .Values.datasetLifecycle.cacheLifetime }} | ||||||||||
ponyisi marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| command: | ||||||||||
|
||||||||||
| command: | |
| command: | |
| - /bin/sh | |
| - -c |
Outdated
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The curl command lacks error handling flags. Add '-f' (fail on HTTP errors) and '--silent' or '--show-error' for better error reporting: curl -f --silent --show-error --request POST ... This ensures the job fails appropriately when the API returns an error.
| - curl --request POST "http://{{ .Release.Name }}-servicex-app:8000/servicex/internal/dataset-lifecycle?age=$LIFETIME" | |
| - curl -f --silent --show-error --request POST "http://{{ .Release.Name }}-servicex-app:8000/servicex/internal/dataset-lifecycle?age=$LIFETIME" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Copyright (c) 2025, IRIS-HEP | ||
| # All rights reserved. | ||
| # | ||
| # Redistribution and use in source and binary forms, with or without | ||
| # modification, are permitted provided that the following conditions are met: | ||
| # | ||
| # * Redistributions of source code must retain the above copyright notice, this | ||
| # list of conditions and the following disclaimer. | ||
| # | ||
| # * Redistributions in binary form must reproduce the above copyright notice, | ||
| # this list of conditions and the following disclaimer in the documentation | ||
| # and/or other materials provided with the distribution. | ||
| # | ||
| # * Neither the name of the copyright holder nor the names of its | ||
| # contributors may be used to endorse or promote products derived from | ||
| # this software without specific prior written permission. | ||
| # | ||
| # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
| # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
| # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| from datetime import datetime, timedelta | ||
|
|
||
| from flask import request, current_app | ||
|
|
||
| from servicex_app.resources.servicex_resource import ServiceXResource | ||
| from ..datasets.get_all import get_all_datasets | ||
| from ..datasets.delete_dataset import delete_dataset | ||
|
|
||
|
|
||
| class DatasetLifecycleOps(ServiceXResource): | ||
| def post(self): | ||
| """ | ||
| Obsolete cached datasets older than N hours | ||
| """ | ||
| now = datetime.now() | ||
ponyisi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try: | ||
| age = float(request.args.get('age', 24)) | ||
| except Exception: | ||
ponyisi marked this conversation as resolved.
Show resolved
Hide resolved
ponyisi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return {"message": "Invalid age parameter"}, 422 | ||
| delta = timedelta(hours=age) | ||
| datasets = get_all_datasets() # by default this will only give non-stale datasets | ||
| todelete = [_.id for _ in datasets if (now-_.last_updated) > delta] | ||
ponyisi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| current_app.logger.info(f"Obsoletion called for datasets older than {delta}. " | ||
| f"Obsoleting {len(todelete)} datasets.") | ||
| for dataset_id in todelete: | ||
| delete_dataset(dataset_id) | ||
ponyisi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return {"message": "Success"}, 200 | ||
Uh oh!
There was an error while loading. Please reload this page.