Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
charlypoly committed Mar 4, 2024
1 parent 36c1904 commit a72d7ce
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 75 deletions.
8 changes: 4 additions & 4 deletions src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,23 @@ export interface Backend {
args: Parameters<F>,
scheduleFor: Date,
discardAfter: Date | undefined,
metadata: { [key: string]: string } | undefined
metadata: { [key: string]: string } | undefined,
): Promise<EnqueueResult>;
getExecution(id: string): Promise<GetExecutionResult>;
getExecutionResult(id: string): Promise<any>;
cancelExecution(id: string, force: boolean): Promise<CancelExecutionResult>;
reRunExecution(id: string): Promise<ReRunExecutionResult>;
rescheduleExecution(
id: string,
scheduleFor: Date
scheduleFor: Date,
): Promise<RescheduleExecutionResult>;
listExecutions(
page?: PageRequest,
filters?: ExecutionFilters
filters?: ExecutionFilters,
): Promise<ListExecutionsResult>;
listExecutionAttempts(
id: string,
page?: PageRequest,
filters?: ExecutionFilters
filters?: ExecutionFilters,
): Promise<ListExecutionAttemptsResult>;
}
32 changes: 16 additions & 16 deletions src/backend/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const banner = `

function paginate<T>(
page: PageRequest | undefined,
records: Map<string, T>
records: Map<string, T>,
): PageResult<T> {
let edges = Array.from(records.keys()).reverse();
let hasNextPage: boolean = false;
Expand Down Expand Up @@ -137,7 +137,7 @@ function paginate<T>(

function isExecutionMatchFilter(
filters: ExecutionFilters | undefined,
execution: InternalExecution<any>
execution: InternalExecution<any>,
): boolean {
if (
filters?.states &&
Expand All @@ -163,13 +163,13 @@ function isExecutionMatchFilter(

if (filters?.metadata && filters.metadata.length > 0 && execution.metadata) {
const metadataFilters = filters.metadata.filter(
(mdFilter) => mdFilter.values.length > 0
(mdFilter) => mdFilter.values.length > 0,
);
if (
!metadataFilters.some((mdFilter) =>
mdFilter.values.some(
(value) => execution.metadata[mdFilter.key] === value
)
(value) => execution.metadata[mdFilter.key] === value,
),
)
) {
return false;
Expand Down Expand Up @@ -264,7 +264,7 @@ async function loop(shouldRun: () => boolean): Promise<void> {
execution.updatedAt = new Date();

return execution;
}
},
);

if (shouldDiscard) {
Expand Down Expand Up @@ -320,7 +320,7 @@ async function loop(shouldRun: () => boolean): Promise<void> {
execution.updatedAt = new Date();
execution.errorCode = errorCode;
return execution;
}
},
);
};

Expand All @@ -342,7 +342,7 @@ export async function enqueue<F extends DeferableFunction>(
args: Parameters<F>,
scheduleFor: Date,
discardAfter: Date | undefined,
metadata: { [key: string]: string } | undefined
metadata: { [key: string]: string } | undefined,
): Promise<EnqueueResult> {
let functionId = functionIdMapping.get(func.__metadata.name);
if (functionId === undefined) {
Expand Down Expand Up @@ -396,7 +396,7 @@ export async function getExecutionResult(id: string): Promise<any> {

export async function cancelExecution(
id: string,
force: boolean
force: boolean,
): Promise<CancelExecutionResult> {
let execution = await executionsStore.get(id);
if (execution === undefined)
Expand All @@ -407,7 +407,7 @@ export async function cancelExecution(
switch (execution.state) {
case "aborting":
throw new ExecutionAbortingAlreadyInProgress(
"aborting execution already in progress"
"aborting execution already in progress",
);
case "created":
execution.state = "cancelled";
Expand All @@ -417,7 +417,7 @@ export async function cancelExecution(
break;
default:
throw new ExecutionNotCancellable(
`cannot cancel execution in "${execution.state}" state`
`cannot cancel execution in "${execution.state}" state`,
);
}
} else {
Expand All @@ -427,7 +427,7 @@ export async function cancelExecution(
break;
default:
throw new ExecutionNotCancellable(
`cannot cancel execution in "${execution.state}" state`
`cannot cancel execution in "${execution.state}" state`,
);
}
}
Expand All @@ -441,7 +441,7 @@ export async function cancelExecution(

export async function rescheduleExecution(
id: string,
scheduleFor: Date
scheduleFor: Date,
): Promise<RescheduleExecutionResult> {
let execution = await executionsStore.get(id);
if (execution === undefined)
Expand All @@ -460,7 +460,7 @@ export async function rescheduleExecution(
}

export async function reRunExecution(
id: string
id: string,
): Promise<ReRunExecutionResult> {
const execution = await executionsStore.get(id);
if (execution === undefined)
Expand All @@ -487,7 +487,7 @@ export async function reRunExecution(

export async function listExecutions(
pageRequest?: PageRequest,
filters?: ExecutionFilters
filters?: ExecutionFilters,
): Promise<ListExecutionsResult> {
const executionIds = await executionsStore.keys();
const data = new Map<string, Execution>();
Expand All @@ -505,7 +505,7 @@ export async function listExecutions(
export async function listExecutionAttempts(
id: string,
pageRequest?: PageRequest,
filters?: ExecutionFilters
filters?: ExecutionFilters,
): Promise<ListExecutionAttemptsResult> {
const executionIds = await executionsStore.keys();
const data = new Map<string, Execution>();
Expand Down
2 changes: 1 addition & 1 deletion src/backend/local/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class KV<T> {

async transaction(
key: string,
setFunc: (value: T) => Promise<T>
setFunc: (value: T) => Promise<T>,
): Promise<T> {
const cur = (await this.get(key)) as T;
const updated = await setFunc(cur);
Expand Down
44 changes: 22 additions & 22 deletions src/backend/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export async function enqueue<F extends DeferableFunction>(
args: Parameters<F>,
scheduleFor: Date,
discardAfter: Date | undefined,
metadata: { [key: string]: string } | undefined
metadata: { [key: string]: string } | undefined,
): Promise<EnqueueResult> {
const httpClient = newClientFromEnv();
const request: CreateExecutionRequest = {
Expand All @@ -167,23 +167,23 @@ export async function enqueue<F extends DeferableFunction>(
const { status, response } = await httpClient<CreateExecutionResponse>(
"PUT",
"/public/v2/executions",
stringify(request)
stringify(request),
);

if (status === 201) return newExecution(response.data);

throw new DeferError(
`backend responds with "${status}" and message "${
(response as any).message
}"`
}"`,
);
}

export async function getExecution(id: string): Promise<GetExecutionResult> {
const httpClient = newClientFromEnv();
const { status, response } = await httpClient<GetExecutionResponse>(
"GET",
`/public/v2/executions/${id}`
`/public/v2/executions/${id}`,
);

if (status === 200) return newExecution(response.data);
Expand All @@ -193,15 +193,15 @@ export async function getExecution(id: string): Promise<GetExecutionResult> {
throw new DeferError(
`backend responds with "${status}" and message "${
(response as any).message
}"`
}"`,
);
}

export async function getExecutionResult(id: string): Promise<any> {
const httpClient = newClientFromEnv();
const { status, response } = await httpClient<GetExecutionResponse>(
"GET",
`/public/v2/executions/${id}/results`
`/public/v2/executions/${id}/results`,
);

if (status === 200) return response;
Expand All @@ -213,20 +213,20 @@ export async function getExecutionResult(id: string): Promise<any> {
throw new DeferError(
`backend responds with "${status}" and message "${
(response as any).message
}"`
}"`,
);
}

export async function cancelExecution(
id: string,
force: boolean
force: boolean,
): Promise<CancelExecutionResult> {
const httpClient = newClientFromEnv();
const request: CancelExecutionRequest = { force: force };
const { status, response } = await httpClient<CancelExecutionResponse>(
"POST",
`/public/v2/executions/${id}/cancellation`,
stringify(request)
stringify(request),
);

if (status === 200) return newExecution(response.data);
Expand All @@ -240,13 +240,13 @@ export async function cancelExecution(
throw new DeferError(
`backend responds with "${status}" and message "${
(response as any).message
}"`
}"`,
);
}

export async function rescheduleExecution(
id: string,
scheduleFor: Date
scheduleFor: Date,
): Promise<RescheduleExecutionResult> {
const httpClient = newClientFromEnv();
const request: RescheduleExecutionRequest = {
Expand All @@ -255,7 +255,7 @@ export async function rescheduleExecution(
const { status, response } = await httpClient<RescheduleExecutionResponse>(
"PATCH",
`/public/v2/executions/${id}/schedule`,
stringify(request)
stringify(request),
);

if (status === 200) return newExecution(response.data);
Expand All @@ -267,19 +267,19 @@ export async function rescheduleExecution(
throw new DeferError(
`backend responds with "${status}" and message "${
(response as any).message
}"`
}"`,
);
}

export async function reRunExecution(
id: string
id: string,
): Promise<ReRunExecutionResult> {
const httpClient = newClientFromEnv();
const request: ReRunExecutionRequest = {};
const { status, response } = await httpClient<ReRunExecutionResponse>(
"POST",
`/public/v2/executions/${id}/reruns`,
stringify(request)
stringify(request),
);

if (status === 200) return newExecution(response.data);
Expand All @@ -289,13 +289,13 @@ export async function reRunExecution(
throw new DeferError(
`backend responds with "${status}" and message "${
(response as any).message
}"`
}"`,
);
}

export async function listExecutions(
pageRequest?: PageRequest,
filters?: ExecutionFilters
filters?: ExecutionFilters,
): Promise<ListExecutionsResult> {
const httpClient = newClientFromEnv();
const request: ListExecutionsRequest = {
Expand All @@ -315,7 +315,7 @@ export async function listExecutions(
const { status, response } = await httpClient<ListExecutionsResponse>(
"POST",
`/public/v2/executions`,
stringify(request)
stringify(request),
);

if (status === 200) {
Expand All @@ -336,14 +336,14 @@ export async function listExecutions(
throw new DeferError(
`backend responds with "${status}" and message "${
(response as any).message
}"`
}"`,
);
}

export async function listExecutionAttempts(
id: string,
pageRequest?: PageRequest,
filters?: ExecutionFilters
filters?: ExecutionFilters,
): Promise<ListExecutionAttemptsResult> {
const httpClient = newClientFromEnv();
const request: ListExecutionAttemptsRequest = {
Expand All @@ -363,7 +363,7 @@ export async function listExecutionAttempts(
const { status, response } = await httpClient<ListExecutionAttemptsResponse>(
"POST",
`/public/v2/executions/${id}/attempts`,
stringify(request)
stringify(request),
);

if (status === 200) {
Expand All @@ -385,6 +385,6 @@ export async function listExecutionAttempts(
throw new DeferError(
`backend responds with "${status}" and message "${
(response as any).message
}"`
}"`,
);
}
6 changes: 3 additions & 3 deletions src/backend/remote/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import VERSION from "../../version.js";
export type HTTPClient = <T>(
method: string,
path: string,
body?: string | null
body?: string | null,
) => Promise<{ status: number; response: T }>;

const basicAuth = (username: string, password: string) => {
Expand All @@ -37,12 +37,12 @@ export class ClientError extends DeferError {
export function makeHTTPClient(
apiEndpoint: string,
accessToken: string,
clientOptions?: RequestInit
clientOptions?: RequestInit,
): HTTPClient {
return async <T>(
method: string,
path: string,
body: string | null = null
body: string | null = null,
): Promise<{ status: number; response: T }> => {
let endpoint;

Expand Down
Loading

0 comments on commit a72d7ce

Please sign in to comment.