@platformatic/control 3.63.0 → 3.64.0

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/lib/errors.d.ts CHANGED
@@ -7,6 +7,8 @@ export declare const ApplicationNotFound: (value: string) => FastifyError
7
7
  export declare const MissingRequestURL: (value: string) => FastifyError
8
8
  export declare const FailedToGetRuntimeMetadata: (value: string) => FastifyError
9
9
  export declare const FailedToGetRuntimeApplications: (value: string) => FastifyError
10
+ export declare const FailedToGetRuntimeScheduler: (value: string) => FastifyError
11
+ export declare const FailedToUpdateRuntimeScheduler: (value: string) => FastifyError
10
12
  export declare const FailedToGetRuntimeEnv: (value: string) => FastifyError
11
13
  export declare const FailedToGetRuntimeOpenapi: (value: string) => FastifyError
12
14
  export declare const FailedToStreamRuntimeLogs: (value: string) => FastifyError
package/lib/errors.js CHANGED
@@ -28,6 +28,16 @@ export const FailedToGetRuntimeOpenapi = createError(
28
28
  'Failed to get runtime OpenAPI schema %s.'
29
29
  )
30
30
 
31
+ export const FailedToGetRuntimeScheduler = createError(
32
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SCHEDULER`,
33
+ 'Failed to get runtime scheduler %s.'
34
+ )
35
+
36
+ export const FailedToUpdateRuntimeScheduler = createError(
37
+ `${ERROR_PREFIX}_FAILED_TO_UPDATE_RUNTIME_SCHEDULER`,
38
+ 'Failed to update runtime scheduler %s.'
39
+ )
40
+
31
41
  export const FailedToStreamRuntimeLogs = createError(
32
42
  `${ERROR_PREFIX}_FAILED_TO_STREAM_RUNTIME_LOGS`,
33
43
  'Failed to stream runtime logs %s.'
package/lib/index.d.ts CHANGED
@@ -94,11 +94,37 @@ export interface LogIndexes {
94
94
  indexes: number[]
95
95
  }
96
96
 
97
+ export interface RuntimeSchedulerJob {
98
+ name: string
99
+ cron: string
100
+ source: 'config' | 'application'
101
+ paused: boolean
102
+ maxRetries: number
103
+ lastExecutedAt: string | null
104
+ lastStatus: 'success' | 'failed' | null
105
+ nextRunAt: string | null
106
+ callbackUrl?: string
107
+ method?: string
108
+ applicationId?: string
109
+ scheduleId?: string
110
+ tasks?: string[]
111
+ }
112
+
113
+ export interface RuntimeSchedulerRunResult {
114
+ name: string
115
+ success: boolean
116
+ executedAt: string
117
+ }
118
+
97
119
  export class RuntimeApiClient {
98
120
  getMatchingRuntime (options?: { pid?: string; name?: string }): Promise<Runtime>
99
121
  getRuntimes (): Promise<Runtime[]>
100
122
  getRuntimeMetadata (pid: number): Promise<Runtime>
101
123
  getRuntimeApplications (pid: number): Promise<RuntimeApplications>
124
+ getRuntimeSchedulerJobs (pid: number): Promise<{ jobs: RuntimeSchedulerJob[] }>
125
+ pauseRuntimeSchedulerJob (pid: number, name: string): Promise<RuntimeSchedulerJob>
126
+ resumeRuntimeSchedulerJob (pid: number, name: string): Promise<RuntimeSchedulerJob>
127
+ runRuntimeSchedulerJob (pid: number, name: string): Promise<RuntimeSchedulerRunResult>
102
128
  getRuntimeConfig (
103
129
  pid: number
104
130
  ): Promise<
package/lib/index.js CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  FailedToGetRuntimeMetadata,
21
21
  FailedToGetRuntimeMetrics,
22
22
  FailedToGetRuntimeOpenapi,
23
+ FailedToGetRuntimeScheduler,
23
24
  FailedToReloadRuntime,
24
25
  FailedToRemoveApplications,
25
26
  FailedToStartProfiling,
@@ -27,6 +28,7 @@ import {
27
28
  FailedToStopRuntime,
28
29
  FailedToStreamRuntimeLogs,
29
30
  FailedToTakeHeapSnapshot,
31
+ FailedToUpdateRuntimeScheduler,
30
32
  ProfilingAlreadyStarted,
31
33
  ProfilingNotStarted,
32
34
  RuntimeNotFound
@@ -193,6 +195,50 @@ export class RuntimeApiClient {
193
195
  return runtimeApplications
194
196
  }
195
197
 
198
+ async getRuntimeSchedulerJobs (pid) {
199
+ const client = this.#getUndiciClient(pid)
200
+
201
+ const { statusCode, body } = await client.request({
202
+ path: '/api/v1/scheduler',
203
+ method: 'GET'
204
+ })
205
+
206
+ if (statusCode !== 200) {
207
+ const error = await body.text()
208
+ throw new FailedToGetRuntimeScheduler(error)
209
+ }
210
+
211
+ return body.json()
212
+ }
213
+
214
+ async pauseRuntimeSchedulerJob (pid, name) {
215
+ return this.#updateRuntimeSchedulerJob(pid, name, 'pause')
216
+ }
217
+
218
+ async resumeRuntimeSchedulerJob (pid, name) {
219
+ return this.#updateRuntimeSchedulerJob(pid, name, 'resume')
220
+ }
221
+
222
+ async runRuntimeSchedulerJob (pid, name) {
223
+ return this.#updateRuntimeSchedulerJob(pid, name, 'run')
224
+ }
225
+
226
+ async #updateRuntimeSchedulerJob (pid, name, action) {
227
+ const client = this.#getUndiciClient(pid)
228
+
229
+ const { statusCode, body } = await client.request({
230
+ path: `/api/v1/scheduler/${encodeURIComponent(name)}/${action}`,
231
+ method: 'POST'
232
+ })
233
+
234
+ if (statusCode !== 200) {
235
+ const error = await body.text()
236
+ throw new FailedToUpdateRuntimeScheduler(error)
237
+ }
238
+
239
+ return body.json()
240
+ }
241
+
196
242
  async getRuntimeConfig (pid, metadata = false) {
197
243
  const client = this.#getUndiciClient(pid)
198
244
 
@@ -347,7 +393,7 @@ export class RuntimeApiClient {
347
393
  async stopApplicationProfiling (pid, applicationId, options = {}) {
348
394
  const client = this.#getUndiciClient(pid)
349
395
 
350
- const { statusCode, body } = await client.request({
396
+ const { statusCode, headers, body } = await client.request({
351
397
  path: `/api/v1/applications/${applicationId}/pprof/stop`,
352
398
  method: 'POST',
353
399
  headers: {
@@ -379,6 +425,21 @@ export class RuntimeApiClient {
379
425
  throw new FailedToStopProfiling(applicationId, message)
380
426
  }
381
427
 
428
+ if (options.allWorkers) {
429
+ // One profile per worker, JSON encoded with base64 payloads
430
+ if (headers['content-type']?.includes('application/json')) {
431
+ const { profiles } = await body.json()
432
+ return profiles.map(({ workerIndex, profile }) => ({
433
+ workerIndex,
434
+ profile: Buffer.from(profile, 'base64')
435
+ }))
436
+ }
437
+
438
+ // Older runtimes ignore the allWorkers option and return a single
439
+ // binary profile from one of the workers.
440
+ return [{ workerIndex: null, profile: Buffer.from(await body.arrayBuffer()) }]
441
+ }
442
+
382
443
  // Return the binary profile data as ArrayBuffer
383
444
  return await body.arrayBuffer()
384
445
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/control",
3
- "version": "3.63.0",
3
+ "version": "3.64.0",
4
4
  "description": "Platformatic Control",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -23,8 +23,8 @@
23
23
  "split2": "^4.2.0",
24
24
  "tstyche": "^6.0.0",
25
25
  "typescript": "^5.9.3",
26
- "@platformatic/runtime": "3.63.0",
27
- "@platformatic/service": "3.63.0"
26
+ "@platformatic/service": "3.64.0",
27
+ "@platformatic/runtime": "3.64.0"
28
28
  },
29
29
  "dependencies": {
30
30
  "@fastify/error": "^4.0.0",
@@ -34,7 +34,7 @@
34
34
  "table": "^6.8.1",
35
35
  "undici": "^7.27.2",
36
36
  "ws": "^8.16.0",
37
- "@platformatic/foundation": "3.63.0"
37
+ "@platformatic/foundation": "3.64.0"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=22.19.0"