Ich habe einen sehr langen Prozess auf Azure. Es kommt vor, dass die Ausführung zu einem zufälligen Zeitpunkt stoppt, ohne ein Protokoll oder eine Fehlermeldung zu hinterlassen. Manchmal läuft es Stunden, manchmal nur ein paar Minuten. Dies passiert nicht auf meinem lokalen PC.App schaltet auf Azure aber nicht auf lokalen PC
Einige Leute haben bereits ähnliche Fragen beantwortet, was darauf hindeutet, dass das Wenden der App auf "Always on" das Problem löst, in meinem Fall aber nicht. Das Problem geht weiter.
Ich habe andere Beiträge zu diesem Thema gelesen und einige Antworten vorgeschlagen, WebJobs zu verwenden. Ich kann nicht, weil meine Anwendung 150 MB hat und die maximale WebJobs-Dateigröße überschreitet.
Über das Projekt: Es ist eine Implementierung eines schweren Gesichtserkennungs- und Erkennungsalgorithmus, der von einer dritten Partei bereitgestellt wird. Der gesamte Code, den ich nicht sehen kann, ist umgeben von try Anweisungen.
Das ist, wie ich die Funktion aufrufe:
Task.Run(()=> loopDeReconhecimento(biometricClient, code, photosInfo,ultimoIndiceReconhecido, totalNumberOfFiles,outPutDestionation));
private async void loopDeReconhecimento(NBiometricClient biometricClient, string code, List<PhotoInfo> photosInfo,int ultimoIndiceReconhecido, int totalNumberOfFiles,string outPutDestionation)
{
WebClient wc = new WebClient();
for (int i = ultimoIndiceReconhecido; i < totalNumberOfFiles; i++)
{
if (forceStop.Contains(code))
{
Log.register(code, "STOPPING!!!!");
forceStop.Remove(code);
return;
}
if (i >= photosInfo.Count)
{
i--;
try
{
Log.register(code, "Fim das fotos upadas por enquanto foi encontrado. Esperando trinta segundos, baixando novamente as informações e tentando de novo " + DateTime.Now.ToLongTimeString());
Thread.Sleep(30000);
wc.DownloadFile(pathWebBase + code + @"/" + @"1.Eventos_grande_simples/imagensConfig.txt", outPutDestionation);
//Log.register(code,"Tempo de download: " + tempoTotal);
PhotoInfo.init(File.ReadAllLines(outPutDestionation), photosInfo);
} catch
{
Log.register(code, "Attempt to download failed. Try again in 30 seconds");
}
continue;
}
Log.register(code, "Starting photo " + i.ToString() + " de " + totalNumberOfFiles);
recognizePhoto(biometricClient,wc, code, photosInfo[i], photosInfo, tentativasPorFoto);
status = i.ToString() + @"/" + totalNumberOfFiles.ToString();
if (forceSave.Contains(code) || (double)i/salvarACadaQuantas == Math.Floor((double)i/salvarACadaQuantas))
{
forceSave.Remove(code);
salvar(i, code, photosInfo);
}
}
Log.register(code, "Fim.");
}
void recognizePhoto(NBiometricClient biometricClient,WebClient wc, string code, PhotoInfo photoInfo, List<PhotoInfo> photosInfo, int attempts)
{
try
{
Log.register(code, "Foto iniciada: " + photoInfo.shortAdress);
NBiometricStatus status;
string localPath = localPathBase + code + @"\Fotos a separar\1.Eventos_grande" + photoInfo.shortAdress;
Stopwatch sw = new Stopwatch();
sw.Start();
NSubject candidateSubject = CreateSubjectFromURL(pathWebBase + code + @"/1.Eventos_grande_simples" + photoInfo.shortAdress, true);
status = biometricClient.CreateTemplate(candidateSubject);
if (status != NBiometricStatus.Ok)
{
Log.register(code, "Template creation was unsuccessful. Status: " + status);
return;
}
else
{
Log.register(code, "Created: Status: " + status);
}
// Set ids to candidate subjects and related subjects
int i = 1;
candidateSubject.Id = "ID_0";
Log.register(code, "Subject na foto: Status: " + candidateSubject.Id);
PersonTagInfo pti = detalharFace(candidateSubject, biometricClient, code);
if (pti != null)
photoInfo.peopleTags.Add(pti);
foreach (var subject in candidateSubject.RelatedSubjects)
{
subject.Id = string.Format("ID_{0}", i++);
Log.register(code, "Subject found in photo: Status: " + subject.Id);
pti = detalharFace(subject, biometricClient, code);
if (pti != null)
photoInfo.peopleTags.Add(pti);
}
identificarESalvarPersonTagInfo(biometricClient, photoInfo, candidateSubject, code);
foreach (NSubject candidato in candidateSubject.RelatedSubjects)
{
identificarESalvarPersonTagInfo(biometricClient, photoInfo, candidato, code);
}
photoInfo.done = true;
Log.register(code, "Tempo de processamento: " + sw.ElapsedMilliseconds);
} catch
{
if (attempts > 0)
{
Log.register(code, "Erro ao processar foto. Tentando novamente em 1 segundo. Tentativas restantes: " + attempts.ToString());
Thread.Sleep(1000);
recognizePhoto(biometricClient,wc, code, photoInfo,photosInfo, attempts - 1);
}
}
}
Können Sie uns einige Details, was diese lange laufenden Prozess ist, wie es ursprünglich implementiert wurde und wie Sie Ihre WebJob ausführbare Datei (ich bin in einer MVC/WebAPI Aktion zur Zeit erraten) (und Abhängigkeiten) überschreitet 150 MB. –
Es verwendet ein SDK von Drittanbietern für Gesichtserkennung und -erkennung. Es wurde ursprünglich als Web-App implementiert. Ich habe die Frage geändert, damit Sie den Code sehen können – Lucas