Created
April 26, 2020 15:31
-
-
Save ndemengel/563a5db021227ab1d7403b01f12eb126 to your computer and use it in GitHub Desktop.
Command queue: specification options
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
/** | |
* Specifies a command to be executed with some arguments. | |
* | |
* For a better development experience, this class must be extended to ensure each command has | |
* an specification type, and must define the queue name via: | |
* - either a static field (for Java classes) named "COMMAND_NAME", | |
* - or a companion object's property (for Kotlin classes) named "COMMAND_NAME". | |
*/ | |
abstract class CommandSpecification( | |
/** | |
* The arguments to be used for the execution. | |
* | |
* Arguments must be very simple JVM types since their are subject to (de-)serialization, | |
* for instance using JSON. | |
*/ | |
val arguments: Map<String, Any?> = emptyMap(), | |
/** | |
* The "weight" of this command with respect to rate limiting. | |
* | |
* If the queue has a rate limiting configuration, then the command specified here will | |
* need to acquire that number of permits to run. | |
*/ | |
val weight: Int = 1, | |
/** | |
* Whether to prevent having the same command specification (name + arguments) waiting | |
* several times for execution during a window configured within the CommandExecutor's | |
* ExecutionPolicy (see property "delayBeforeConsideringTask"). | |
* | |
* Said another way: for X exact same command specifications scheduled on that window, | |
* only one will be executed. | |
* | |
* Of course, a new command specification is still taken into account when past specifications | |
* have been executed. | |
* | |
* @see ExecutionPolicy.delayBeforeConsideringTask | |
*/ | |
val deduplicate: Boolean = true, | |
/** | |
* Whether to prevent running the task described by this specification (command name | |
* + arguments) when the same task is currently being executed (i.e. locked). | |
* (The difference with "deduplicate" is that the deduplication only occurs for pending | |
* tasks.) | |
*/ | |
val preventConcurrentRunIfDuplicate: Boolean = true | |
) { | |
val commandName get() = getCommandName(this) | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment