Skip to content
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

Disable audio transcription if initialization fails when creating reports (#2381) #2382

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class RemoteTranscriptionTask extends AbstractTranscriptTask {

private static AtomicBoolean statsPrinted = new AtomicBoolean();

private static volatile AtomicBoolean init = new AtomicBoolean();

private static long lastUpdateServersTime = 0;

private static class Server {
Expand All @@ -81,7 +83,7 @@ public void init(ConfigurationManager configurationManager) throws Exception {

super.init(configurationManager);

if (!this.isEnabled()) {
if (!isEnabled()) {
return;
}

Expand Down Expand Up @@ -115,8 +117,21 @@ public void init(ConfigurationManager configurationManager) throws Exception {
return;
}

requestServers(true);

synchronized (init) {
if (!init.get()) {
try {
requestServers(true);
} catch (Exception e) {
if (hasIpedDatasource()) {
transcriptConfig.setEnabled(false);
logger.warn("Could not initialize remote transcription. Task disabled.");
} else {
throw e;
}
}
init.set(true);
}
}
}

private static synchronized void requestServers(RemoteTranscriptionTask task, boolean now) throws IOException {
Expand Down Expand Up @@ -163,7 +178,7 @@ private void requestServers(boolean now) throws IOException {
@Override
public void finish() throws Exception {
super.finish();
if (!statsPrinted.getAndSet(true)) {
if (isEnabled() && !statsPrinted.getAndSet(true)) {
int numWorkers = this.worker.manager.getNumWorkers();
DecimalFormat df = new DecimalFormat();
logger.info("Time spent to send audios: {}s", df.format(audioSendingTime.get() / (1000 * numWorkers)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.InputStreamReader;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.commons.lang3.SystemUtils;
import org.apache.logging.log4j.Level;
Expand Down Expand Up @@ -42,6 +43,8 @@ public class Wav2Vec2TranscriptTask extends AbstractTranscriptTask {

protected static volatile Level logLevel = Level.forName("MSG", 250);

private static volatile AtomicBoolean init = new AtomicBoolean();

static class Server {
Process process;
BufferedReader reader;
Expand All @@ -68,7 +71,7 @@ public void init(ConfigurationManager configurationManager) throws Exception {

super.init(configurationManager);

if (!this.isEnabled()) {
if (!isEnabled()) {
return;
}

Expand All @@ -85,11 +88,26 @@ public void init(ConfigurationManager configurationManager) throws Exception {

if (!deque.isEmpty())
return;

Server server;
int device = 0;
while ((server = startServer(device++)) != null) {
deque.add(server);

synchronized (init) {
if (!init.get()) {
try {
Server server;
int device = 0;
while ((server = startServer(device++)) != null) {
deque.add(server);
}

} catch (Exception e) {
if (hasIpedDatasource()) {
transcriptConfig.setEnabled(false);
logger.warn("Could not initialize audio transcription. Task disabled.");
} else {
throw e;
}
}
init.set(true);
}
}

logLevel = Level.DEBUG;
Expand Down
Loading