Added explicit stdout print and direct task execution
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
##
|
||||||
|
#
|
||||||
|
# Command: python manage.py run_asyncron_task
|
||||||
|
#
|
||||||
|
##
|
||||||
|
|
||||||
|
import traceback, logging
|
||||||
|
import asyncio
|
||||||
|
import time
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
from asyncron.models import Task
|
||||||
|
|
||||||
|
class bcolors:
|
||||||
|
HEADER = '\033[95m'
|
||||||
|
OKBLUE = '\033[94m'
|
||||||
|
OKCYAN = '\033[96m'
|
||||||
|
OKGREEN = '\033[92m'
|
||||||
|
WARNING = '\033[93m'
|
||||||
|
FAIL = '\033[91m'
|
||||||
|
ENDC = '\033[0m'
|
||||||
|
BOLD = '\033[1m'
|
||||||
|
UNDERLINE = '\033[4m'
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Start an Asyncorn Worker'
|
||||||
|
|
||||||
|
def handle( self, *args, task_name, **kwargs ):
|
||||||
|
|
||||||
|
task = Task.objects.filter( name__endswith = task_name ).first()
|
||||||
|
if not task:
|
||||||
|
print("Could not find this task, these are the options:\n", "\n - ".join( Task.registered_tasks ))
|
||||||
|
return
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
print(f"Running Task: {task}")
|
||||||
|
trace = task.new_trace()
|
||||||
|
trace.show_prints = True
|
||||||
|
asyncio.run( trace.start() )
|
||||||
|
trace.save()
|
||||||
|
|
||||||
|
def add_arguments( self, parser ):
|
||||||
|
parser.add_argument('task_name', default = "")
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
+3
-1
@@ -239,5 +239,7 @@ class Trace( BaseModel ):
|
|||||||
|
|
||||||
def print( self, *args, sep = " ", end = "\n", file = None, flush = True ): #We get 'file' here to fool tasks that aren't self_aware
|
def print( self, *args, sep = " ", end = "\n", file = None, flush = True ): #We get 'file' here to fool tasks that aren't self_aware
|
||||||
assert hasattr(self, 'commit_on_new_print_task'), "trace.print needs to be called while a trace.commit_on_new_print task is active!"
|
assert hasattr(self, 'commit_on_new_print_task'), "trace.print needs to be called while a trace.commit_on_new_print task is active!"
|
||||||
self.stdout += sep.join( str(i) for i in args ) + end
|
string = sep.join( str(i) for i in args ) + end
|
||||||
|
self.stdout += string
|
||||||
if flush: self.new_print.set()
|
if flush: self.new_print.set()
|
||||||
|
if getattr(self, "show_prints", False): print( string )
|
||||||
|
|||||||
Reference in New Issue
Block a user