@cycleplatform/api-client-typescript 0.3.0 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/dist/index.js +315 -175
- package/dist/index.umd.cjs +1 -1
- package/package.json +7 -7
- package/src/generated/types.ts +3642 -1019
- package/src/index.ts +3 -1
- package/src/jobs.ts +167 -0
package/README.md
CHANGED
|
@@ -65,6 +65,44 @@ const resp = await client.GET("/v1/containers/{containerId}", {
|
|
|
65
65
|
console.log(resp.data, resp.error);
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
+
### Tracking a Job
|
|
69
|
+
|
|
70
|
+
Cycle utilizes an asynchronous job system for handling background tasks. Often it is useful to keep tabs on the
|
|
71
|
+
progress of these jobs, or to wait for a job to complete (or fail) before continuing. This API client includes
|
|
72
|
+
a job tracking utility function to simplify this process.
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { client, trackJob } from "@cycleplatform/api-client-typescript";
|
|
76
|
+
|
|
77
|
+
const baseUrl = "https://api.cycle.io";
|
|
78
|
+
|
|
79
|
+
const client = getClient({
|
|
80
|
+
baseUrl,
|
|
81
|
+
apiKey: "<your-api-key>",
|
|
82
|
+
hubId: "<your-hub-id>",
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const tracker = trackJob(client, "<job-id>");
|
|
86
|
+
|
|
87
|
+
// It's possible to listen for progress updates on a job as it executes
|
|
88
|
+
tracker.addEventListener("progress", (event) => {
|
|
89
|
+
console.log((event as CustomEvent).detail);
|
|
90
|
+
// {
|
|
91
|
+
// total: number;
|
|
92
|
+
// completed: number;
|
|
93
|
+
// failed: number;
|
|
94
|
+
// percent: number;
|
|
95
|
+
// state: components["schemas"]["JobState"]["current"];
|
|
96
|
+
// }
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Wait for job to complete
|
|
100
|
+
const job = await tracker.promise;
|
|
101
|
+
console.log(job.state.current); // "completed"
|
|
102
|
+
|
|
103
|
+
// throws on job failure
|
|
104
|
+
```
|
|
105
|
+
|
|
68
106
|
## Development
|
|
69
107
|
|
|
70
108
|
### Cloning submodules
|