-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at deleting backfill runs.
- Loading branch information
1 parent
a9b4121
commit c3a815a
Showing
21 changed files
with
363 additions
and
83 deletions.
There are no files selected for viewing
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
43 changes: 43 additions & 0 deletions
43
service/src/main/kotlin/app/cash/backfila/dashboard/CancelBackfillAction.kt
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,43 @@ | ||
package app.cash.backfila.dashboard | ||
|
||
import app.cash.backfila.service.persistence.BackfillState | ||
import javax.inject.Inject | ||
import misk.MiskCaller | ||
import misk.scope.ActionScoped | ||
import misk.security.authz.Authenticated | ||
import misk.web.PathParam | ||
import misk.web.Post | ||
import misk.web.RequestBody | ||
import misk.web.RequestContentType | ||
import misk.web.ResponseContentType | ||
import misk.web.actions.WebAction | ||
import misk.web.mediatype.MediaTypes | ||
import wisp.logging.getLogger | ||
|
||
class CancelBackfillRequest | ||
class CancelBackfillResponse | ||
|
||
class CancelBackfillAction @Inject constructor( | ||
private val caller: @JvmSuppressWildcards ActionScoped<MiskCaller?>, | ||
private val backfillStateToggler: BackfillStateToggler | ||
) : WebAction { | ||
|
||
@Post("/backfills/{id}/cancel") | ||
@RequestContentType(MediaTypes.APPLICATION_JSON) | ||
@ResponseContentType(MediaTypes.APPLICATION_JSON) | ||
// TODO allow any user | ||
@Authenticated(capabilities = ["users"]) | ||
fun cancel( | ||
@PathParam id: Long, | ||
@RequestBody request: CancelBackfillRequest | ||
): CancelBackfillResponse { | ||
// TODO check user has permissions for this service with access api | ||
logger.info { "Canceling backfill $id by ${caller.get()?.user}" } | ||
backfillStateToggler.toggleRunningState(id, caller.get()!!, BackfillState.CANCELLED) | ||
return CancelBackfillResponse() | ||
} | ||
|
||
companion object { | ||
private val logger = getLogger<CancelBackfillAction>() | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
service/src/main/kotlin/app/cash/backfila/service/persistence/BackfillPartitionState.kt
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,13 @@ | ||
package app.cash.backfila.service.persistence | ||
|
||
enum class BackfillPartitionState { | ||
PAUSED, // A resumable backfill partition that is not currently meant to be running | ||
RUNNING, // A backfill partition that is allowed to run. | ||
COMPLETE, // A completed partition, this is a final non-resumable state. | ||
STALE, // A partition that is no longer relevant, this is a final non-resumable state (possibly a split partition) | ||
CANCELLED; // A partition that has been manually cancelled, this is a final non-resumable state. | ||
|
||
companion object { | ||
val FINAL_STATES = setOf(STALE, CANCELLED, COMPLETE) | ||
} | ||
} |
21 changes: 18 additions & 3 deletions
21
service/src/main/kotlin/app/cash/backfila/service/persistence/BackfillState.kt
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 |
---|---|---|
@@ -1,7 +1,22 @@ | ||
package app.cash.backfila.service.persistence | ||
|
||
enum class BackfillState { | ||
PAUSED, | ||
RUNNING, | ||
COMPLETE | ||
PAUSED, // A resumable backfill that is not currently meant to be running | ||
RUNNING, // A backfill that is allowed to run. | ||
COMPLETE, // A completed backfill, this is a final non-resumable state. | ||
CANCELLED; // A backfill that has been manually cancelled, this is a final non-resumable state. | ||
|
||
companion object { | ||
val FINAL_STATES = setOf(CANCELLED, COMPLETE) | ||
|
||
/** | ||
* When the Backfill state changes modify the underlying partitions to these corresponding states. | ||
*/ | ||
fun BackfillState.getPartitionState() = when (this) { | ||
PAUSED -> BackfillPartitionState.PAUSED | ||
RUNNING -> BackfillPartitionState.RUNNING | ||
CANCELLED -> BackfillPartitionState.CANCELLED | ||
COMPLETE -> BackfillPartitionState.COMPLETE | ||
} | ||
} | ||
} |
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
Oops, something went wrong.