17
17
18
18
using ServerlessWorkflow . Sdk ;
19
19
20
- namespace Synapse . Application . Commands . Schedules ;
21
-
22
- /// <summary>
23
- /// Represents the <see cref="ICommand"/> used to complete a <see cref="V1Schedule"/>'s occurence
24
- /// </summary>
25
- [ DataTransferObjectType ( typeof ( Integration . Commands . Schedules . V1CompleteScheduleOccurenceCommand ) ) ]
26
- public class V1CompleteScheduleOccurenceCommand
27
- : Command < Integration . Models . V1Schedule >
20
+ namespace Synapse . Application . Commands . Schedules
28
21
{
29
22
30
23
/// <summary>
31
- /// Initializes a new <see cref="V1CompleteScheduleOccurenceCommand "/>
24
+ /// Represents the <see cref="ICommand"/> used to complete a <see cref="V1Schedule "/>'s occurence
32
25
/// </summary>
33
- protected V1CompleteScheduleOccurenceCommand ( ) { }
34
26
35
- /// <summary>
36
- /// Initializes a new <see cref="V1CompleteScheduleOccurenceCommand"/>
37
- /// </summary>
38
- /// <param name="scheduleId">The id of the <see cref="V1Schedule"/> to complete an occurence of</param>
39
- /// <param name="workflowInstanceId">The id of the <see cref="V1WorkflowInstance"/> that has been executed</param>
40
- public V1CompleteScheduleOccurenceCommand ( string scheduleId , string workflowInstanceId )
27
+ public class V1CompleteScheduleOccurenceCommand
28
+ : Command < Integration . Models . V1Schedule >
41
29
{
42
- this . ScheduleId = scheduleId ;
43
- this . WorkflowInstanceId = workflowInstanceId ;
44
- }
45
30
46
- /// <summary>
47
- /// Gets the id of the <see cref="V1Schedule "/> to complete an occurence of
48
- /// </summary>
49
- public virtual string ScheduleId { get ; protected set ; } = null ! ;
31
+ /// <summary>
32
+ /// Initializes a new <see cref="V1CompleteScheduleOccurenceCommand "/>
33
+ /// </summary>
34
+ protected V1CompleteScheduleOccurenceCommand ( ) { }
50
35
51
- /// <summary>
52
- /// Gets the id of the <see cref="V1WorkflowInstance"/> that has been executed
53
- /// </summary>
54
- public virtual string WorkflowInstanceId { get ; protected set ; } = null ! ;
36
+ /// <summary>
37
+ /// Initializes a new <see cref="V1CompleteScheduleOccurenceCommand"/>
38
+ /// </summary>
39
+ /// <param name="scheduleId">The id of the <see cref="V1Schedule"/> to complete an occurence of</param>
40
+ /// <param name="workflowInstanceId">The id of the <see cref="V1WorkflowInstance"/> that has been executed</param>
41
+ public V1CompleteScheduleOccurenceCommand ( string scheduleId , string workflowInstanceId )
42
+ {
43
+ this . ScheduleId = scheduleId ;
44
+ this . WorkflowInstanceId = workflowInstanceId ;
45
+ }
55
46
56
- }
47
+ /// <summary>
48
+ /// Gets the id of the <see cref="V1Schedule"/> to complete an occurence of
49
+ /// </summary>
50
+ public virtual string ScheduleId { get ; protected set ; } = null ! ;
57
51
58
- /// <summary>
59
- /// Represents the service used to handle <see cref="V1CompleteScheduleOccurenceCommand"/>s
60
- /// </summary>
61
- public class V1CompleteScheduleOccurenceCommandHandler
62
- : CommandHandlerBase ,
63
- ICommandHandler < V1CompleteScheduleOccurenceCommand , Integration . Models . V1Schedule >
64
- {
52
+ /// <summary>
53
+ /// Gets the id of the <see cref="V1WorkflowInstance"/> that has been executed
54
+ /// </summary>
55
+ public virtual string WorkflowInstanceId { get ; protected set ; } = null ! ;
65
56
66
- /// <summary>
67
- /// Initializes a new <see cref="V1CompleteScheduleOccurenceCommandHandler"/>
68
- /// </summary>
69
- /// <param name="loggerFactory">The service used to create <see cref="ILogger"/>s</param>
70
- /// <param name="mediator">The service used to mediate calls</param>
71
- /// <param name="mapper">The service used to map objects</param>
72
- /// <param name="schedules">The <see cref="IRepository"/> used to manage <see cref="V1Schedule"/>s</param>
73
- /// <param name="backgroundJobManager">The service used to manage background jobs</param>
74
- public V1CompleteScheduleOccurenceCommandHandler ( ILoggerFactory loggerFactory , IMediator mediator , IMapper mapper , IRepository < V1Schedule > schedules , IBackgroundJobManager backgroundJobManager )
75
- : base ( loggerFactory , mediator , mapper )
76
- {
77
- this . Schedules = schedules ;
78
- this . BackgroundJobManager = backgroundJobManager ;
79
57
}
80
58
81
59
/// <summary>
82
- /// Gets the <see cref="IRepository"/> used to manage <see cref="V1Schedule "/>s
60
+ /// Represents the service used to handle <see cref="V1CompleteScheduleOccurenceCommand "/>s
83
61
/// </summary>
84
- protected IRepository < V1Schedule > Schedules { get ; }
62
+ public class V1CompleteScheduleOccurenceCommandHandler
63
+ : CommandHandlerBase ,
64
+ ICommandHandler < V1CompleteScheduleOccurenceCommand , Integration . Models . V1Schedule >
65
+ {
85
66
86
- /// <summary>
87
- /// Gets the service used to manage background jobs
88
- /// </summary>
89
- protected IBackgroundJobManager BackgroundJobManager { get ; }
67
+ /// <summary>
68
+ /// Initializes a new <see cref="V1CompleteScheduleOccurenceCommandHandler"/>
69
+ /// </summary>
70
+ /// <param name="loggerFactory">The service used to create <see cref="ILogger"/>s</param>
71
+ /// <param name="mediator">The service used to mediate calls</param>
72
+ /// <param name="mapper">The service used to map objects</param>
73
+ /// <param name="schedules">The <see cref="IRepository"/> used to manage <see cref="V1Schedule"/>s</param>
74
+ /// <param name="backgroundJobManager">The service used to manage background jobs</param>
75
+ public V1CompleteScheduleOccurenceCommandHandler ( ILoggerFactory loggerFactory , IMediator mediator , IMapper mapper , IRepository < V1Schedule > schedules , IBackgroundJobManager backgroundJobManager )
76
+ : base ( loggerFactory , mediator , mapper )
77
+ {
78
+ this . Schedules = schedules ;
79
+ this . BackgroundJobManager = backgroundJobManager ;
80
+ }
81
+
82
+ /// <summary>
83
+ /// Gets the <see cref="IRepository"/> used to manage <see cref="V1Schedule"/>s
84
+ /// </summary>
85
+ protected IRepository < V1Schedule > Schedules { get ; }
86
+
87
+ /// <summary>
88
+ /// Gets the service used to manage background jobs
89
+ /// </summary>
90
+ protected IBackgroundJobManager BackgroundJobManager { get ; }
91
+
92
+ /// <inheritdoc/>
93
+ public virtual async Task < IOperationResult < Integration . Models . V1Schedule > > HandleAsync ( V1CompleteScheduleOccurenceCommand command , CancellationToken cancellationToken = default )
94
+ {
95
+ var schedule = await this . Schedules . FindAsync ( command . ScheduleId , cancellationToken ) ;
96
+ if ( schedule == null ) throw DomainException . NullReference ( typeof ( V1Schedule ) , command . ScheduleId ) ;
97
+ schedule . CompleteOccurence ( command . WorkflowInstanceId ) ;
98
+ await this . Schedules . UpdateAsync ( schedule , cancellationToken ) ;
99
+ await this . Schedules . SaveChangesAsync ( cancellationToken ) ;
100
+ if ( schedule . Definition . Type == ScheduleDefinitionType . Interval && schedule . NextOccurenceAt . HasValue ) await this . BackgroundJobManager . ScheduleJobAsync ( schedule , cancellationToken ) ;
101
+ return this . Ok ( this . Mapper . Map < Integration . Models . V1Schedule > ( schedule ) ) ;
102
+ }
90
103
91
- /// <inheritdoc/>
92
- public virtual async Task < IOperationResult < Integration . Models . V1Schedule > > HandleAsync ( V1CompleteScheduleOccurenceCommand command , CancellationToken cancellationToken = default )
93
- {
94
- var schedule = await this . Schedules . FindAsync ( command . ScheduleId , cancellationToken ) ;
95
- if ( schedule == null ) throw DomainException . NullReference ( typeof ( V1Schedule ) , command . ScheduleId ) ;
96
- schedule . CompleteOccurence ( command . WorkflowInstanceId ) ;
97
- await this . Schedules . UpdateAsync ( schedule , cancellationToken ) ;
98
- await this . Schedules . SaveChangesAsync ( cancellationToken ) ;
99
- if ( schedule . Definition . Type == ScheduleDefinitionType . Interval && schedule . NextOccurenceAt . HasValue ) await this . BackgroundJobManager . ScheduleJobAsync ( schedule , cancellationToken ) ;
100
- return this . Ok ( this . Mapper . Map < Integration . Models . V1Schedule > ( schedule ) ) ;
101
104
}
102
105
103
106
}
0 commit comments