-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2809 from PrefectHQ/dylan/enhancement/worker-util…
…ities Enhancement: useWorker
- Loading branch information
Showing
5 changed files
with
49 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useSubscriptionWithDependencies } from '@prefecthq/vue-compositions' | ||
import { computed, MaybeRefOrGetter, toRef, toValue } from 'vue' | ||
import { useCan } from '@/compositions/useCan' | ||
import { useWorkspaceApi } from '@/compositions/useWorkspaceApi' | ||
import { WorkspaceWorkPoolWorkersApi } from '@/services' | ||
import { Getter } from '@/types/reactivity' | ||
import { UseEntitySubscription } from '@/types/useEntitySubscription' | ||
|
||
export type UseWorker = UseEntitySubscription<WorkspaceWorkPoolWorkersApi['getWorker'], 'worker'> | ||
|
||
export function useWorker(workPoolName: MaybeRefOrGetter<string | null | undefined>, workerId: MaybeRefOrGetter<string | null | undefined>): UseWorker { | ||
const api = useWorkspaceApi() | ||
const can = useCan() | ||
|
||
const getter: Getter<[string, string] | null> = () => { | ||
if (!can.read.worker) { | ||
return null | ||
} | ||
|
||
const name = toValue(workPoolName) | ||
const id = toValue(workerId) | ||
|
||
if (!name || !id) { | ||
return null | ||
} | ||
|
||
return [name, id] | ||
} | ||
|
||
const parameters = toRef(getter) | ||
|
||
const subscription = useSubscriptionWithDependencies(api.workPoolWorkers.getWorker, parameters) | ||
const worker = computed(() => subscription.response) | ||
|
||
return { | ||
subscription, | ||
worker, | ||
} | ||
} |
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