Skip to content

Commit

Permalink
Merge pull request #206 from CMSTrackerDPG/#203
Browse files Browse the repository at this point in the history
Management command to clear running status for all scripts [Closes #203]
  • Loading branch information
nothingface0 authored Aug 23, 2022
2 parents e3f7b14 + e08a9c4 commit b9e8d38
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions openshift-start-up-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

python manage.py collectstatic --noinput
python manage.py migrate --run-syncdb
python manage.py clear_scripts_running_status

daphne -b 0.0.0.0 -p 8080 dqmhelper.asgi:application
1 change: 1 addition & 0 deletions remotescripts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs):
class RemoteScriptConfigurationAdmin(admin.ModelAdmin):
list_display = ("title", "num_pos_args", "num_kw_args", "num_output_files")
actions = [execute]
exclude = ["is_running"]

def num_pos_args(self, obj):
return obj.positional_arguments.count()
Expand Down
25 changes: 25 additions & 0 deletions remotescripts/management/commands/clear_scripts_running_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.core.management.base import BaseCommand, CommandError
from remotescripts.models import ScriptConfigurationBase


class Command(BaseCommand):
help = (
"Clears the running status of all remotescripts. To be used on server restart"
)

def handle(self, *args, **options):
scripts = ScriptConfigurationBase.objects.all()
count = 0
for script in scripts:
if script.is_running:
script.is_running = False
script.save()
count += 1
if count:
self.stdout.write(
self.style.SUCCESS("Cleared 'running' status of %s scripts" % count)
)
else:
self.stdout.write(
self.style.SUCCESS("No scripts with status 'running' were found")
)

0 comments on commit b9e8d38

Please sign in to comment.