Hello:
[note this App is connected via uplink code - to the local server side also]
I am trying to download and then transcribe an audio (or video) file. I have the code working to handle the transcription and it works from the Anvil App as long as the transcribing does not time out –
So using the background task tutorial I created the functionality to do it in a background task.
However I am not able to get the background task to do anything. It does not create a background task in the logging section or show any active background task running.
I tried to start the task from the anvil.server level (server module/web-side) and also tried to do it from callable functions at the server-side (local uplink connected callable code).
In the code below you will see a function called (as the background_task)
anvil.server.launch_background_task(‘downloadMediaFile’,file)
Please note that when I remove the background_task decorator and replace it with ‘callable’ decorator and run it as shown below - the function works and if the audio file is short enough, returns with the proper results.
anvil.server.call(‘downloadMediaFile’,file)
But when I try to run it as a background task – nothing at all happens at all - the form function times out and presents the message : “anvil.server.TimeoutError: Server code took too long”
I cloned the background_task example and it works but it is not involving the uplink side of this operation. I would expect to be able to print a message when the start_background method is called - so there is no way to prove that it even calls that function.
A frustrating hour trying to figure this out – likely it is right in front of me – thank you in advance for any help.
Code Sample:
## the background task method
@anvil.server.background_task
def downloadMediaFile(file):
paths = db.get_site_paths('singletranscripts')
code_path = paths['code_path']
file_path = paths['file_path']
print (f"doing the download ")
maketranscript = single_transcript.CreateTranscriptFromFile()
manager = maketranscript.manage_transcript(file,code_path,file_path)
## the calling method
@anvil.server.callable
def start_file_transcribe_background_task(file):
print('in the starter')
#results = anvil.server.call('downloadMediaFile',file)
task = anvil.server.launch_background_task('downloadMediaFile',file)
return task
## code in the form
print(f"The file's name is: {file.name}")
print(f"The number of bytes in the file is: {file.length}")
print(f"The file's content type is: {file.content_type}")
self.title_of_file.text = f"Transcribing {file.name}"
#results = anvil.server.call('downloadMediaFile',file)
self.wait_message.text = 'Get Some Coffee This Will Take a Few Minutes ...'
results = anvil.server.call('start_file_transcribe_background_task',file)
# paste your code between ```
Clone link:
share a copy of your app