Skip to content

Commit 4cc6005

Browse files
committed
Cleanup.
Signed-off-by: Alexander Trauzzi <[email protected]>
1 parent b0bd1b7 commit 4cc6005

File tree

7 files changed

+85
-87
lines changed

7 files changed

+85
-87
lines changed

src/implementation/Client/GRPCClient/jobs.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ limitations under the License.
1313

1414
import IClientJobs from "../../../interfaces/Client/IClientJobs";
1515
import GRPCClient from "./GRPCClient";
16+
import { JobSchedule } from "../../../types/jobs/JobSchedule.type";
17+
import { Job } from "../../../types/jobs/Job.type";
1618

1719

1820
export default class GRPCClientJobs implements IClientJobs {
@@ -23,13 +25,22 @@ export default class GRPCClientJobs implements IClientJobs {
2325
this.grpcClient = grpcClient;
2426
}
2527

26-
schedule(): Promise<unknown> {
28+
async schedule(
29+
jobName: string,
30+
data: object | string,
31+
schedule: JobSchedule | null = null,
32+
dueTime: string | Date | null = null,
33+
repeats: number | null = null,
34+
ttl: string | null = null
35+
): Promise<void> {
2736
throw new Error("Not yet!");
2837
}
29-
get(): Promise<unknown> {
38+
39+
async get<DataType>(jobName: string): Promise<Job<DataType>> {
3040
throw new Error("Not yet!");
3141
}
32-
delete(): Promise<unknown> {
42+
43+
async delete(jobName: string): Promise<void> {
3344
throw new Error("Not yet!");
3445
}
3546
}

src/implementation/Client/HTTPClient/jobs.ts

Lines changed: 42 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,58 +19,45 @@ import { JobSchedule } from "../../../types/jobs/JobSchedule.type";
1919

2020
export default class HTTPClientJobs implements IClientJobs {
2121

22-
constructor(private readonly httpClient: HTTPClient) {}
23-
24-
async schedule(
25-
jobName: string,
26-
data: object | string,
27-
schedule: JobSchedule | null = null,
28-
dueTime: string | Date | null = null,
29-
repeats: number | null = null,
30-
ttl: string | null = null
31-
): Promise<void> {
32-
33-
await this.httpClient.executeWithApiVersion(
34-
"v1.0-alpha1",
35-
`/jobs/${jobName}`,
36-
{
37-
method: "POST",
38-
body: {
39-
data,
40-
schedule,
41-
dueTime,
42-
repeats,
43-
ttl,
44-
},
45-
headers: {
46-
"content-type": "application/json",
47-
},
48-
} as THTTPExecuteParams
49-
);
50-
}
51-
52-
async get(jobName: string): Promise<Job>;
53-
async get<DataType>(jobName: string): Promise<Job<DataType>> {
54-
55-
const result = await this.httpClient.executeWithApiVersion(
56-
"v1.0-alpha1",
57-
`/jobs/${jobName}`,
58-
{
59-
method: "GET",
60-
}
61-
);
62-
63-
return result as Job<DataType>;
64-
}
65-
66-
async delete(jobName: string): Promise<void> {
67-
68-
await this.httpClient.executeWithApiVersion(
69-
"v1.0-alpha1",
70-
`/jobs/${jobName}`,
71-
{
72-
method: "DELETE"
73-
}
74-
);
75-
}
76-
}
22+
private static ApiVersion = "v1.0-alpha1";
23+
private static Path = "jobs";
24+
25+
constructor(private readonly httpClient: HTTPClient) {}
26+
27+
async schedule(
28+
jobName: string,
29+
data: object | string,
30+
schedule: JobSchedule | null = null,
31+
dueTime: string | Date | null = null,
32+
repeats: number | null = null,
33+
ttl: string | null = null,
34+
): Promise<void> {
35+
await this.httpClient.executeWithApiVersion(HTTPClientJobs.ApiVersion, `/${HTTPClientJobs.Path}/${jobName}`, {
36+
method: "POST",
37+
body: {
38+
data,
39+
schedule,
40+
dueTime,
41+
repeats,
42+
ttl,
43+
},
44+
headers: {
45+
"content-type": "application/json",
46+
},
47+
} as THTTPExecuteParams);
48+
}
49+
50+
async get<DataType>(jobName: string): Promise<Job<DataType>> {
51+
const result = await this.httpClient.executeWithApiVersion(HTTPClientJobs.ApiVersion, `/${HTTPClientJobs.Path}/${jobName}`, {
52+
method: "GET",
53+
});
54+
55+
return result as Job<DataType>;
56+
}
57+
58+
async delete(jobName: string): Promise<void> {
59+
await this.httpClient.executeWithApiVersion(HTTPClientJobs.ApiVersion, `/${HTTPClientJobs.Path}/${jobName}`, {
60+
method: "DELETE",
61+
});
62+
}
63+
}

src/implementation/Server/HTTPServer/jobs.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ import HTTPServer from "./HTTPServer";
1616
import { TypeDaprJobsCallback } from "../../../types/DaprJobsCallback.type";
1717

1818
export default class HTTPServerJobs implements IServerJobs {
19+
constructor(private readonly httpServer: HTTPServer) {}
1920

20-
constructor(private readonly httpServer: HTTPServer) {}
21-
22-
listen(jobName: string, callback: TypeDaprJobsCallback) : void;
23-
listen<DataType>(jobName: string, callback: TypeDaprJobsCallback<DataType>): void {
24-
this.httpServer.getServer().post(`/job/${jobName}`, callback);
25-
}
21+
listen<DataType>(jobName: string, callback: TypeDaprJobsCallback<DataType>): void {
22+
this.httpServer.getServer().post(`/job/${jobName}`, callback);
23+
}
2624
}

src/interfaces/Client/IClientJobs.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ import { JobSchedule } from "../../types/jobs/JobSchedule.type";
1515
import { Job } from "../../types/jobs/Job.type";
1616

1717
export default interface IClientJobs {
18+
schedule(
19+
jobName: string,
20+
data: object | string,
21+
schedule: JobSchedule | null,
22+
dueTime: string | Date | null,
23+
repeats: number | null,
24+
ttl: string | null,
25+
): Promise<void>;
1826

19-
schedule(
20-
jobName: string,
21-
data: object | string,
22-
schedule: JobSchedule | null,
23-
dueTime: string | Date | null,
24-
repeats: number | null,
25-
ttl: string | null
26-
): Promise<void>;
27-
get(jobName: string): Promise<Job>;
28-
delete(jobName: string): Promise<void>;
27+
get(jobName: string): Promise<Job>;
28+
get<DataType>(jobName: string): Promise<Job<DataType>>;
29+
30+
delete(jobName: string): Promise<void>;
2931
}

src/interfaces/Server/IServerJobs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ limitations under the License.
1414
import { TypeDaprJobsCallback } from "../../types/DaprJobsCallback.type";
1515

1616
export default interface IServerJobs {
17+
listen(jobName: string, callback: TypeDaprJobsCallback): void;
1718

18-
listen(jobName: string, callback: TypeDaprJobsCallback): void;
19-
20-
}
19+
listen<DataType>(jobName: string, callback: TypeDaprJobsCallback<DataType>): void;
20+
}

src/types/jobs/Job.type.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ limitations under the License.
1414
import { JobSchedule } from "./JobSchedule.type";
1515

1616
export interface Job<DataType = object | string> {
17-
name: string;
18-
schedule: JobSchedule;
19-
data: {
20-
value: DataType,
21-
};
17+
name: string;
18+
schedule: JobSchedule;
19+
data: {
20+
value: DataType;
21+
};
2222
}

src/types/jobs/JobSchedule.type.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ limitations under the License.
1212
*/
1313

1414
export enum FixedPeriod {
15-
Yearly = "@yearly",
16-
Monthly = "@monthly",
17-
Weekly = "@weekly",
18-
Daily = "@daily",
19-
Hourly = "@hourly"
15+
Yearly = "@yearly",
16+
Monthly = "@monthly",
17+
Weekly = "@weekly",
18+
Daily = "@daily",
19+
Hourly = "@hourly",
2020
}
2121

2222
type EveryPeriod = `@every ${string}`;

0 commit comments

Comments
 (0)