-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Acquisition Filters for More Complex States
like AniDB, Network, Database
- Loading branch information
Showing
26 changed files
with
156 additions
and
35 deletions.
There are no files selected for viewing
5 changes: 0 additions & 5 deletions
5
Shoko.Server/Scheduling/Acquisition/AniDBHTTPRateLimitedAttribute.cs
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
Shoko.Server/Scheduling/Acquisition/AniDBUDPRateLimitedAttribute.cs
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
Shoko.Server/Scheduling/Acquisition/Attributes/AcquisitionFilterAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using System; | ||
|
||
namespace Shoko.Server.Scheduling.Acquisition.Attributes; | ||
|
||
public abstract class AcquisitionFilterAttribute : Attribute { } |
6 changes: 6 additions & 0 deletions
6
Shoko.Server/Scheduling/Acquisition/Attributes/AniDBHttpRateLimitedAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using System; | ||
|
||
namespace Shoko.Server.Scheduling.Acquisition.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Class)] | ||
public class AniDBHttpRateLimitedAttribute : AcquisitionFilterAttribute { } |
6 changes: 6 additions & 0 deletions
6
Shoko.Server/Scheduling/Acquisition/Attributes/AniDBUdpRateLimitedAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using System; | ||
|
||
namespace Shoko.Server.Scheduling.Acquisition.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Class)] | ||
public class AniDBUdpRateLimitedAttribute : AcquisitionFilterAttribute { } |
6 changes: 6 additions & 0 deletions
6
Shoko.Server/Scheduling/Acquisition/Attributes/DatabaseRequiredAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using System; | ||
|
||
namespace Shoko.Server.Scheduling.Acquisition.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Class)] | ||
public class DatabaseRequiredAttribute : AcquisitionFilterAttribute { } |
6 changes: 6 additions & 0 deletions
6
Shoko.Server/Scheduling/Acquisition/Attributes/NetworkRequiredAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using System; | ||
|
||
namespace Shoko.Server.Scheduling.Acquisition.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Class)] | ||
public class NetworkRequiredAttribute : AcquisitionFilterAttribute { } |
6 changes: 0 additions & 6 deletions
6
Shoko.Server/Scheduling/Acquisition/DatabaseRequiredAttribute.cs
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
Shoko.Server/Scheduling/Acquisition/Filters/AniDBHttpRateLimitedAcquisitionFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Linq; | ||
using Quartz; | ||
using Quartz.Util; | ||
using Shoko.Server.Providers.AniDB.Interfaces; | ||
using Shoko.Server.Scheduling.Acquisition.Attributes; | ||
|
||
namespace Shoko.Server.Scheduling.Acquisition.Filters; | ||
|
||
public class AniDBHttpRateLimitedAcquisitionFilter : IAcquisitionFilter | ||
{ | ||
private readonly Type[] _types; | ||
private readonly IHttpConnectionHandler _connectionHandler; | ||
|
||
public AniDBHttpRateLimitedAcquisitionFilter(IHttpConnectionHandler connectionHandler) | ||
{ | ||
_connectionHandler = connectionHandler; | ||
_types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(a => | ||
typeof(IJob).IsAssignableFrom(a) && !a.IsAbstract && ObjectUtils.IsAttributePresent(a, typeof(AniDBHttpRateLimitedAttribute))).ToArray(); | ||
} | ||
|
||
public Type[] GetTypesToExclude() => _connectionHandler.IsBanned ? _types : Array.Empty<Type>(); | ||
} |
23 changes: 23 additions & 0 deletions
23
Shoko.Server/Scheduling/Acquisition/Filters/AniDBUdpRateLimitedAcquisitionFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Linq; | ||
using Quartz; | ||
using Quartz.Util; | ||
using Shoko.Server.Providers.AniDB.Interfaces; | ||
using Shoko.Server.Scheduling.Acquisition.Attributes; | ||
|
||
namespace Shoko.Server.Scheduling.Acquisition.Filters; | ||
|
||
public class AniDBUdpRateLimitedAcquisitionFilter : IAcquisitionFilter | ||
{ | ||
private readonly Type[] _types; | ||
private readonly IUDPConnectionHandler _connectionHandler; | ||
|
||
public AniDBUdpRateLimitedAcquisitionFilter(IUDPConnectionHandler connectionHandler) | ||
{ | ||
_connectionHandler = connectionHandler; | ||
_types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(a => | ||
typeof(IJob).IsAssignableFrom(a) && !a.IsAbstract && ObjectUtils.IsAttributePresent(a, typeof(AniDBUdpRateLimitedAttribute))).ToArray(); | ||
} | ||
|
||
public Type[] GetTypesToExclude() => _connectionHandler.IsBanned || _connectionHandler.IsInvalidSession ? _types : Array.Empty<Type>(); | ||
} |
21 changes: 21 additions & 0 deletions
21
Shoko.Server/Scheduling/Acquisition/Filters/DatabaseRequiredAcquisitionFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Linq; | ||
using Quartz; | ||
using Quartz.Util; | ||
using Shoko.Server.Scheduling.Acquisition.Attributes; | ||
using Shoko.Server.Server; | ||
|
||
namespace Shoko.Server.Scheduling.Acquisition.Filters; | ||
|
||
public class DatabaseRequiredAcquisitionFilter : IAcquisitionFilter | ||
{ | ||
private readonly Type[] _types; | ||
|
||
public DatabaseRequiredAcquisitionFilter() | ||
{ | ||
_types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(a => | ||
typeof(IJob).IsAssignableFrom(a) && !a.IsAbstract && ObjectUtils.IsAttributePresent(a, typeof(DatabaseRequiredAttribute))).ToArray(); | ||
} | ||
|
||
public Type[] GetTypesToExclude() => ServerState.Instance.ServerOnline && !ServerState.Instance.DatabaseBlocked.Blocked ? Array.Empty<Type>() : _types; | ||
} |
8 changes: 8 additions & 0 deletions
8
Shoko.Server/Scheduling/Acquisition/Filters/IAcquisitionFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System; | ||
|
||
namespace Shoko.Server.Scheduling.Acquisition.Filters; | ||
|
||
public interface IAcquisitionFilter | ||
{ | ||
Type[] GetTypesToExclude(); | ||
} |
24 changes: 24 additions & 0 deletions
24
Shoko.Server/Scheduling/Acquisition/Filters/NetworkRequiredAcquisitionFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Quartz; | ||
using Quartz.Util; | ||
using Shoko.Server.Scheduling.Acquisition.Attributes; | ||
using Shoko.Server.Services.Connectivity; | ||
|
||
namespace Shoko.Server.Scheduling.Acquisition.Filters; | ||
|
||
public class NetworkRequiredAcquisitionFilter : IAcquisitionFilter | ||
{ | ||
private readonly Type[] _types; | ||
private readonly IConnectivityMonitor[] _connectivityMonitors; | ||
|
||
public NetworkRequiredAcquisitionFilter(IEnumerable<IConnectivityMonitor> connectivityMonitors) | ||
{ | ||
_connectivityMonitors = connectivityMonitors.ToArray(); | ||
_types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(a => | ||
typeof(IJob).IsAssignableFrom(a) && !a.IsAbstract && ObjectUtils.IsAttributePresent(a, typeof(NetworkRequiredAttribute))).ToArray(); | ||
} | ||
|
||
public Type[] GetTypesToExclude() => _connectivityMonitors.Any(a => a.HasConnected) ? Array.Empty<Type>() : _types; | ||
} |
6 changes: 0 additions & 6 deletions
6
Shoko.Server/Scheduling/Acquisition/NetworkRequiredAttribute.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters