@@ -12,6 +12,7 @@ limitations under the License.
1212*/
1313
1414import DaprClient from "../../implementation/Client/DaprClient" ;
15+ import { Logger } from "../../logger/Logger" ;
1516import Class from "../../types/Class" ;
1617import ActorId from "../ActorId" ;
1718import AbstractActor from "./AbstractActor" ;
@@ -23,11 +24,17 @@ import BufferSerializer from "./BufferSerializer";
2324 * The Actor Manager manages actor objects of a specific actor type
2425 */
2526const REMINDER_METHOD_NAME = "receiveReminder" ; // the callback method name for the reminder
27+ export enum DeactivateResult {
28+ Success ,
29+ ActorDoesNotExist ,
30+ Error ,
31+ }
2632
2733export default class ActorManager < T extends AbstractActor > {
2834 readonly actorCls : Class < T > ;
2935 readonly daprClient : DaprClient ;
3036 readonly serializer : BufferSerializer = new BufferSerializer ( ) ;
37+ readonly logger : Logger ;
3138
3239 actors : Map < string , T > ;
3340
@@ -39,6 +46,7 @@ export default class ActorManager<T extends AbstractActor> {
3946 this . daprClient = daprClient ;
4047 this . actorCls = actorCls ;
4148
49+ this . logger = new Logger ( "Actors" , "ActorManager" , daprClient . options . logger ) ;
4250 this . actors = new Map < string , T > ( ) ;
4351
4452 // @todo : we need to make sure race condition cannot happen when accessing the active actors
@@ -71,20 +79,21 @@ export default class ActorManager<T extends AbstractActor> {
7179 this . actors . set ( actorId . getId ( ) , actor ) ;
7280 }
7381
74- async deactivateActor ( actorId : ActorId ) : Promise < void > {
75- if ( ! this . actors . has ( actorId . getId ( ) ) ) {
76- throw new Error (
77- JSON . stringify ( {
78- error : "ACTOR_NOT_ACTIVATED" ,
79- errorMsg : `The actor ${ actorId . getId ( ) } was not activated` ,
80- } ) ,
81- ) ;
82+ async deactivateActor ( actorId : ActorId ) : Promise < DeactivateResult > {
83+ if ( this . actors . has ( actorId . getId ( ) ) ) {
84+ try {
85+ const actor = await this . getActiveActor ( actorId ) ;
86+ await actor . onDeactivateInternal ( ) ;
87+ return DeactivateResult . Success ;
88+ } catch ( error ) {
89+ this . logger . error ( "Error encountered deactivating actor" ) ;
90+ }
91+ this . actors . delete ( actorId . getId ( ) ) ;
92+ } else {
93+ this . logger . warn ( `The actor ${ actorId . getId ( ) } was not activated` ) ;
94+ return DeactivateResult . ActorDoesNotExist ;
8295 }
83-
84- const actor = await this . getActiveActor ( actorId ) ;
85- await actor . onDeactivateInternal ( ) ;
86-
87- this . actors . delete ( actorId . getId ( ) ) ;
96+ return DeactivateResult . Error ;
8897 }
8998
9099 async getActiveActor ( actorId : ActorId ) : Promise < T > {
0 commit comments