tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
EventConsumer.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Threading;
4using System.Threading.Tasks;
5
8
10{
13 {
18
23
29 {
30 this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
31 }
32
34 public ValueTask? HandleCustomEvent(string eventName, IEnumerable<string?> parameters, CancellationToken cancellationToken)
35 => configuration.HandleCustomEvent(eventName, parameters, cancellationToken);
36
38 public async ValueTask HandleEvent(EventType eventType, IEnumerable<string?> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
39 {
40 ArgumentNullException.ThrowIfNull(parameters);
41
42 if (watchdog == null)
43 throw new InvalidOperationException("EventConsumer used without watchdog set!");
44
45 var scriptTask = configuration.HandleEvent(eventType, parameters, deploymentPipeline, cancellationToken);
46 await watchdog.HandleEvent(eventType, parameters, deploymentPipeline, cancellationToken);
47 await scriptTask;
48 }
49
55 {
56 ArgumentNullException.ThrowIfNull(watchdog);
57 var oldWatchdog = Interlocked.CompareExchange(ref this.watchdog, watchdog, null);
58 if (oldWatchdog != null)
59 throw new InvalidOperationException("watchdog already set!");
60 }
61 }
62}
IWatchdog? watchdog
The IWatchdog for the EventConsumer.
readonly IConfiguration configuration
The IConfiguration for the EventConsumer.
async ValueTask HandleEvent(EventType eventType, IEnumerable< string?> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
Handle a given eventType .A ValueTask representing the running operation.
void SetWatchdog(IWatchdog watchdog)
Set the watchdog for the EventConsumer.
EventConsumer(IConfiguration configuration)
Initializes a new instance of the EventConsumer class.
ValueTask? HandleCustomEvent(string eventName, IEnumerable< string?> parameters, CancellationToken cancellationToken)
Handles a given custom event.A ValueTask representing the running operation if the event was triggere...
Consumes EventTypes and takes the appropriate actions.
ValueTask? HandleCustomEvent(string eventName, IEnumerable< string?> parameters, CancellationToken cancellationToken)
Handles a given custom event.
ValueTask HandleEvent(EventType eventType, IEnumerable< string?> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
Handle a given eventType .
Runs and monitors the twin server controllers.
Definition IWatchdog.cs:16
EventType
Types of events. Mirror in tgs.dm. Prefer last listed name for script.
Definition EventType.cs:7