mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(transcribe): persist vocabularies across restart (#1608)
Back the Transcribe vocabulary store with StorageFactory (constructor-injected) and add a transcribe storage mode + flush-interval config, so custom vocabularies survive a restart instead of being held only in memory. Adds a persistence test covering the reload round-trip.
This commit is contained in:
1 parent
dcc90031c5
commit
239bc52e06
6 files changed
+112
-2
No files matched your search
@@ -193,6 +193,7 @@ public interface EmulatorConfig {
|
||||
CodeBuildStorageConfig codebuild();
|
||||
ConfigStorageConfig config();
|
||||
CodeDeployStorageConfig codedeploy();
|
||||
TranscribeStorageConfig transcribe();
|
||||
}
|
||||
|
||||
interface SsmStorageConfig {
|
||||
@@ -366,6 +367,13 @@ public interface EmulatorConfig {
|
||||
long flushIntervalMs();
|
||||
}
|
||||
|
||||
interface TranscribeStorageConfig {
|
||||
Optional<String> mode();
|
||||
|
||||
@WithDefault("5000")
|
||||
long flushIntervalMs();
|
||||
}
|
||||
|
||||
interface CodeDeployStorageConfig {
|
||||
Optional<String> mode();
|
||||
|
||||
|
||||
@@ -320,7 +320,8 @@ public class ResolvedServiceCatalog {
|
||||
protocols(ServiceProtocol.JSON),
|
||||
Set.of("AWSPriceListService."), Set.of("pricing", "api.pricing"), Set.of(), Set.of()),
|
||||
descriptor("transcribe", "transcribe", config.services().transcribe().enabled(), true,
|
||||
null, null, 5000L, null, ServiceProtocol.JSON,
|
||||
"transcribe", storageMode(config.storage().services().transcribe().mode(), config.storage().mode()),
|
||||
config.storage().services().transcribe().flushIntervalMs(), null, ServiceProtocol.JSON,
|
||||
protocols(ServiceProtocol.JSON),
|
||||
Set.of("Transcribe."), Set.of("transcribe"), Set.of(), Set.of()),
|
||||
descriptor("ce", "ce", config.services().ce().enabled(), true,
|
||||
|
||||
+24
-1
@@ -1,14 +1,20 @@
|
||||
package io.github.hectorvent.floci.services.transcribe;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackedMap;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.transcribe.model.TranscriptionJob;
|
||||
import io.github.hectorvent.floci.services.transcribe.model.TranscriptionJobSummary;
|
||||
import io.github.hectorvent.floci.services.transcribe.model.VocabularyInfo;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
@@ -20,8 +26,25 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
@ApplicationScoped
|
||||
public class TranscribeService {
|
||||
|
||||
private final StorageFactory storageFactory;
|
||||
|
||||
// Transcription jobs are transient (async work deleted after processing); vocabularies are durable.
|
||||
private final ConcurrentHashMap<String, TranscriptionJob> transcriptionJobs = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, VocabularyInfo> vocabularies = new ConcurrentHashMap<>();
|
||||
private Map<String, VocabularyInfo> vocabularies = new ConcurrentHashMap<>();
|
||||
|
||||
@Inject
|
||||
public TranscribeService(StorageFactory storageFactory) {
|
||||
this.storageFactory = storageFactory;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
void initializeStorage() {
|
||||
if (storageFactory == null) {
|
||||
return; // keeps non-CDI unit tests working
|
||||
}
|
||||
this.vocabularies = new StorageBackedMap<>(storageFactory.create("transcribe",
|
||||
"transcribe-vocabularies.json", new TypeReference<Map<String, VocabularyInfo>>() {}));
|
||||
}
|
||||
|
||||
public TranscriptionJob startTranscriptionJob(String jobName, String mediaFileUri,
|
||||
String languageCode, String mediaFormat) {
|
||||
|
||||
Reference in new issue
Block a user