-
-
Notifications
You must be signed in to change notification settings - Fork 743
MarQS reserve concurrency system & queue priority for resuming/retrying #1715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
511a97c
run engine v1: orgs are no longer considered for concurrency
ericallam ac8fa75
Add reserve concurrency concept to allow waiting to resume parent tas…
ericallam 7061d3a
child tasks inherit the queue timestamp from their parent tasks to pr…
ericallam 0587b5a
handle reserve concurrency with recursive deadlocks
ericallam 67f2f8b
Finish docs update for concurrency
ericallam bb53fc5
Some fixes from badge conflict resolution
ericallam 61fab3d
WIP priority queues
ericallam 32817f9
Implement MarQS priority queues
ericallam 84f5563
Fix the migrations
ericallam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,340 @@ | ||
import { useIsImpersonating } from "~/hooks/useOrganizations"; | ||
import { useHasAdminAccess } from "~/hooks/useUser"; | ||
import { Button } from "../primitives/Buttons"; | ||
import { Dialog, DialogContent, DialogHeader, DialogTrigger } from "../primitives/Dialog"; | ||
import { Cog6ToothIcon } from "@heroicons/react/20/solid"; | ||
import { type loader } from "~/routes/resources.taskruns.$runParam.debug"; | ||
import { UseDataFunctionReturn, useTypedFetcher } from "remix-typedjson"; | ||
import { useEffect } from "react"; | ||
import { Spinner } from "../primitives/Spinner"; | ||
import * as Property from "~/components/primitives/PropertyTable"; | ||
import { ClipboardField } from "../primitives/ClipboardField"; | ||
import { MarQSShortKeyProducer } from "~/v3/marqs/marqsKeyProducer"; | ||
|
||
export function AdminDebugRun({ friendlyId }: { friendlyId: string }) { | ||
const hasAdminAccess = useHasAdminAccess(); | ||
const isImpersonating = useIsImpersonating(); | ||
|
||
if (!hasAdminAccess && !isImpersonating) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Dialog key={`debug-${friendlyId}`}> | ||
<DialogTrigger asChild> | ||
<Button variant="tertiary/small" LeadingIcon={Cog6ToothIcon}> | ||
Debug run | ||
</Button> | ||
</DialogTrigger> | ||
<DebugRunDialog friendlyId={friendlyId} /> | ||
</Dialog> | ||
); | ||
} | ||
|
||
export function DebugRunDialog({ friendlyId }: { friendlyId: string }) { | ||
return ( | ||
<DialogContent | ||
key={`debug`} | ||
className="overflow-y-auto sm:h-[80vh] sm:max-h-[80vh] sm:max-w-[50vw]" | ||
> | ||
<DebugRunContent friendlyId={friendlyId} /> | ||
</DialogContent> | ||
); | ||
} | ||
|
||
function DebugRunContent({ friendlyId }: { friendlyId: string }) { | ||
const fetcher = useTypedFetcher<typeof loader>(); | ||
const isLoading = fetcher.state === "loading"; | ||
|
||
useEffect(() => { | ||
fetcher.load(`/resources/taskruns/${friendlyId}/debug`); | ||
}, [friendlyId]); | ||
|
||
return ( | ||
<> | ||
<DialogHeader>Debugging run</DialogHeader> | ||
{isLoading ? ( | ||
<div className="grid place-items-center p-6"> | ||
<Spinner /> | ||
</div> | ||
) : fetcher.data ? ( | ||
<DebugRunData {...fetcher.data} /> | ||
) : ( | ||
<>Failed to get run debug data</> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
function DebugRunData({ | ||
run, | ||
queueConcurrencyLimit, | ||
queueCurrentConcurrency, | ||
envConcurrencyLimit, | ||
envCurrentConcurrency, | ||
queueReserveConcurrency, | ||
envReserveConcurrency, | ||
}: UseDataFunctionReturn<typeof loader>) { | ||
const keys = new MarQSShortKeyProducer("marqs:"); | ||
|
||
const withPrefix = (key: string) => `marqs:${key}`; | ||
|
||
return ( | ||
<Property.Table> | ||
<Property.Item> | ||
<Property.Label>ID</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField value={run.id} variant="tertiary/small" iconButton /> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Message key</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={withPrefix(keys.messageKey(run.id))} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>GET message</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={`GET ${withPrefix(keys.messageKey(run.id))}`} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Queue key</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={withPrefix( | ||
keys.queueKey(run.runtimeEnvironment, run.queue, run.concurrencyKey ?? undefined) | ||
)} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Get queue set</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={`ZRANGE ${withPrefix( | ||
keys.queueKey(run.runtimeEnvironment, run.queue, run.concurrencyKey ?? undefined) | ||
)} 0 -1`} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Queue current concurrency key</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={withPrefix( | ||
keys.queueCurrentConcurrencyKey( | ||
run.runtimeEnvironment, | ||
run.queue, | ||
run.concurrencyKey ?? undefined | ||
) | ||
)} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
|
||
<Property.Item> | ||
<Property.Label>Get queue current concurrency</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={`SMEMBERS ${withPrefix( | ||
keys.queueCurrentConcurrencyKey( | ||
run.runtimeEnvironment, | ||
run.queue, | ||
run.concurrencyKey ?? undefined | ||
) | ||
)}`} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Queue current concurrency</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<span>{queueCurrentConcurrency ?? "0"}</span> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Queue reserve concurrency key</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={withPrefix( | ||
keys.queueReserveConcurrencyKeyFromQueue( | ||
keys.queueKey(run.runtimeEnvironment, run.queue, run.concurrencyKey ?? undefined) | ||
) | ||
)} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
|
||
<Property.Item> | ||
<Property.Label>Get queue reserve concurrency</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={`SMEMBERS ${withPrefix( | ||
keys.queueReserveConcurrencyKeyFromQueue( | ||
keys.queueKey(run.runtimeEnvironment, run.queue, run.concurrencyKey ?? undefined) | ||
) | ||
)}`} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Queue reserve concurrency</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<span>{queueReserveConcurrency ?? "0"}</span> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Queue concurrency limit key</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={withPrefix(keys.queueConcurrencyLimitKey(run.runtimeEnvironment, run.queue))} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>GET queue concurrency limit</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={`GET ${withPrefix( | ||
keys.queueConcurrencyLimitKey(run.runtimeEnvironment, run.queue) | ||
)}`} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Queue concurrency limit</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<span>{queueConcurrencyLimit ?? "Not set"}</span> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Env current concurrency key</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={withPrefix(keys.envCurrentConcurrencyKey(run.runtimeEnvironment))} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Get env current concurrency</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={`SMEMBERS ${withPrefix(keys.envCurrentConcurrencyKey(run.runtimeEnvironment))}`} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Env current concurrency</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<span>{envCurrentConcurrency ?? "0"}</span> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Env reserve concurrency key</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={withPrefix(keys.envReserveConcurrencyKey(run.runtimeEnvironment.id))} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Get env reserve concurrency</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={`SMEMBERS ${withPrefix( | ||
keys.envReserveConcurrencyKey(run.runtimeEnvironment.id) | ||
)}`} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Env reserve concurrency</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<span>{envReserveConcurrency ?? "0"}</span> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Env concurrency limit key</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={withPrefix(keys.envConcurrencyLimitKey(run.runtimeEnvironment))} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>GET env concurrency limit</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={`GET ${withPrefix(keys.envConcurrencyLimitKey(run.runtimeEnvironment))}`} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Env concurrency limit</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<span>{envConcurrencyLimit ?? "Not set"}</span> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Shared queue key</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={`GET ${withPrefix(keys.envSharedQueueKey(run.runtimeEnvironment))}`} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
<Property.Item> | ||
<Property.Label>Get shared queue set</Property.Label> | ||
<Property.Value className="flex items-center gap-2"> | ||
<ClipboardField | ||
value={`ZRANGEBYSCORE ${withPrefix( | ||
keys.envSharedQueueKey(run.runtimeEnvironment) | ||
)} -inf ${Date.now()} WITHSCORES`} | ||
variant="tertiary/small" | ||
iconButton | ||
/> | ||
</Property.Value> | ||
</Property.Item> | ||
</Property.Table> | ||
); | ||
} | ||
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.