@@ -12,6 +12,7 @@ limitations under the License.
12
12
*/
13
13
14
14
import DaprClient from "../../implementation/Client/DaprClient" ;
15
+ import { Logger } from "../../logger/Logger" ;
15
16
import Class from "../../types/Class" ;
16
17
import ActorId from "../ActorId" ;
17
18
import AbstractActor from "./AbstractActor" ;
@@ -23,11 +24,17 @@ import BufferSerializer from "./BufferSerializer";
23
24
* The Actor Manager manages actor objects of a specific actor type
24
25
*/
25
26
const REMINDER_METHOD_NAME = "receiveReminder" ; // the callback method name for the reminder
27
+ export enum DeactivateResult {
28
+ Success ,
29
+ ActorDoesNotExist ,
30
+ Error ,
31
+ }
26
32
27
33
export default class ActorManager < T extends AbstractActor > {
28
34
readonly actorCls : Class < T > ;
29
35
readonly daprClient : DaprClient ;
30
36
readonly serializer : BufferSerializer = new BufferSerializer ( ) ;
37
+ readonly logger : Logger ;
31
38
32
39
actors : Map < string , T > ;
33
40
@@ -39,6 +46,7 @@ export default class ActorManager<T extends AbstractActor> {
39
46
this . daprClient = daprClient ;
40
47
this . actorCls = actorCls ;
41
48
49
+ this . logger = new Logger ( "Actors" , "ActorManager" , daprClient . options . logger ) ;
42
50
this . actors = new Map < string , T > ( ) ;
43
51
44
52
// @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> {
71
79
this . actors . set ( actorId . getId ( ) , actor ) ;
72
80
}
73
81
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 ;
82
95
}
83
-
84
- const actor = await this . getActiveActor ( actorId ) ;
85
- await actor . onDeactivateInternal ( ) ;
86
-
87
- this . actors . delete ( actorId . getId ( ) ) ;
96
+ return DeactivateResult . Error ;
88
97
}
89
98
90
99
async getActiveActor ( actorId : ActorId ) : Promise < T > {
0 commit comments