Skip to content

Commit 90133c8

Browse files
author
Richard Lyle
committed
* NaturalLanguageClassifier & DIalog now do more extensive testing to verify the service is up and running.
* TODO: Need to add the concept of a deep/shallow check for the service status checks.
1 parent c24d676 commit 90133c8

File tree

2 files changed

+88
-18
lines changed

2 files changed

+88
-18
lines changed

Scripts/Services/Dialog/Dialog.cs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,20 +452,53 @@ private class CheckServiceStatus
452452
{
453453
private Dialog m_Service = null;
454454
private ServiceStatus m_Callback = null;
455+
private int m_DialogCount = 0;
455456

456457
public CheckServiceStatus( Dialog service, ServiceStatus callback )
457458
{
458459
m_Service = service;
459460
m_Callback = callback;
460461

461462
if (! m_Service.GetDialogs( OnGetDialogs ) )
462-
m_Callback( SERVICE_ID, false );
463+
OnFailure( "Failed to invoke GetDialogs()." );
463464
}
464465

465466
private void OnGetDialogs( Dialogs dialogs )
466467
{
467-
if ( m_Callback != null )
468-
m_Callback( SERVICE_ID, dialogs != null );
468+
if ( m_Callback != null )
469+
{
470+
foreach( var dialog in dialogs.dialogs )
471+
{
472+
if (! m_Service.Converse( dialog.dialog_id, "Hello", OnDialog ) )
473+
OnFailure( "Failed to invoke Converse()." );
474+
else
475+
m_DialogCount += 1;
476+
}
477+
}
478+
else
479+
OnFailure( "GetDialogs() failed." );
480+
}
481+
482+
private void OnDialog( ConverseResponse resp )
483+
{
484+
if ( m_DialogCount > 0 )
485+
{
486+
m_DialogCount -= 1;
487+
if ( resp != null )
488+
{
489+
if ( m_DialogCount == 0 )
490+
m_Callback( SERVICE_ID, true );
491+
}
492+
else
493+
OnFailure( "ConverseResponse is null." );
494+
}
495+
}
496+
497+
private void OnFailure(string msg)
498+
{
499+
Log.Error("NaturalLanguageClassifier", msg);
500+
m_Callback(SERVICE_ID, false);
501+
m_DialogCount = 0;
469502
}
470503
};
471504
#endregion

Scripts/Services/NaturalLanguageClassifier/NaturalLanguageClassifier.cs

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,16 @@ private class CheckServiceStatus
504504
{
505505
private NaturalLanguageClassifier m_Service = null;
506506
private ServiceStatus m_Callback = null;
507+
private int m_GetClassifierCount = 0;
508+
private int m_ClassifyCount = 0;
507509

508510
public CheckServiceStatus( NaturalLanguageClassifier service, ServiceStatus callback )
509511
{
510512
m_Service = service;
511513
m_Callback = callback;
512514

513515
if (! m_Service.GetClassifiers( OnCheckServices ) )
514-
m_Callback( SERVICE_ID, false );
516+
OnFailure( "Failed to call GetClassifiers()" );
515517
}
516518

517519
private void OnCheckServices( Classifiers classifiers )
@@ -520,9 +522,17 @@ private void OnCheckServices( Classifiers classifiers )
520522
{
521523
if ( classifiers.classifiers.Length > 0 )
522524
{
523-
// check the status of one classifier, if it's listed as "Unavailable" then fail
524-
if (! m_Service.GetClassifier( classifiers.classifiers[0].classifier_id, OnCheckService ) )
525-
m_Callback( SERVICE_ID, false );
525+
foreach( var classifier in classifiers.classifiers )
526+
{
527+
// check the status of one classifier, if it's listed as "Unavailable" then fail
528+
if (! m_Service.GetClassifier( classifier.classifier_id, OnCheckService ) )
529+
{
530+
OnFailure( "Failed to call GetClassifier()" );
531+
break;
532+
}
533+
else
534+
m_GetClassifierCount += 1;
535+
}
526536
}
527537
else
528538
m_Callback( SERVICE_ID, true ); // no classifiers to check, just return success then..
@@ -533,26 +543,53 @@ private void OnCheckServices( Classifiers classifiers )
533543

534544
private void OnCheckService( Classifier classifier )
535545
{
536-
if ( classifier != null )
546+
if ( m_GetClassifierCount > 0 )
537547
{
538-
if ( classifier.status == "Unavailable" || classifier.status == "Failed" )
548+
m_GetClassifierCount -= 1;
549+
if ( classifier != null )
539550
{
540-
Log.Error( "NaturalLanguageClassifier", "Status of classifier {0} came back as {1}.",
541-
classifier.classifier_id, classifier.status );
542-
m_Callback( SERVICE_ID, false );
551+
if ( classifier.status == "Unavailable" || classifier.status == "Failed" )
552+
{
553+
OnFailure( string.Format("Status of classifier {0} came back as {1}.",
554+
classifier.classifier_id, classifier.status) );
555+
}
556+
else
557+
{
558+
// try to classify something with this classifier..
559+
if (! m_Service.Classify( classifier.classifier_id, "Hello World", OnClassify ) )
560+
OnFailure( "Failed to invoke Classify" );
561+
else
562+
m_ClassifyCount += 1;
563+
}
543564
}
544565
else
545-
{
546-
m_Callback( SERVICE_ID, true );
547-
}
566+
OnFailure( "Failed to get classifier." );
548567
}
549-
else
568+
}
569+
570+
private void OnClassify( ClassifyResult result )
571+
{
572+
if ( m_ClassifyCount > 0 )
550573
{
551-
Log.Error( "NaturalLanguageClassifier", "Failed to get classifier." );
552-
m_Callback( SERVICE_ID, false );
574+
m_ClassifyCount -= 1;
575+
if ( result != null )
576+
{
577+
// success!
578+
if ( m_ClassifyCount == 0 )
579+
m_Callback(SERVICE_ID, true);
580+
}
581+
else
582+
OnFailure( "Failed to classify." );
553583
}
554584
}
555585

586+
void OnFailure( string msg )
587+
{
588+
Log.Error( "NaturalLanguageClassifier", msg );
589+
m_Callback(SERVICE_ID, false);
590+
m_GetClassifierCount = m_ClassifyCount = 0;
591+
}
592+
556593
};
557594
#endregion
558595
}

0 commit comments

Comments
 (0)