Skip to content

Commit e2eb2fc

Browse files
committed
Fix scheduler create
1 parent ee329ea commit e2eb2fc

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

examples/schedule.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@ import { SchedulerClient } from '../index.js'
22

33
export const createSchedule =
44
({ log }) =>
5-
async (scheduleName) => {
5+
async (scheduleName, arn, roleArn) => {
66
const client = new SchedulerClient({
77
log
88
})
9-
return client.createSchedule(scheduleName, {})
9+
return client.createSchedule(scheduleName, {
10+
scheduleExpression: 'rate(1 minute)',
11+
flexibleTimeWindow: { mode: 'OFF' },
12+
input: { foo: 'bar' },
13+
target: {
14+
arn,
15+
roleArn,
16+
eventBridgeParameters: {
17+
detailType: 'example',
18+
source: 'example'
19+
}
20+
}
21+
})
1022
}
1123

1224
export const deleteSchedule =

lib/clients/scheduler.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ import {
77
} from '@aws-sdk/client-scheduler'
88
import { v4 as uuidv4 } from 'uuid'
99
import { createLogger } from '@meltwater/mlabs-logger'
10+
import {
11+
has,
12+
identity,
13+
ifElse,
14+
isObjLike,
15+
isObjectLike,
16+
map,
17+
mapPath,
18+
pipe
19+
} from '@meltwater/phi'
1020

1121
import { createCache } from '../cache.js'
1222
import { keysToCamelCase, keysToPascalCase } from '../case.js'
@@ -134,5 +144,34 @@ export class SchedulerClient {
134144
}
135145
}
136146

137-
const formatReq = keysToPascalCase
138-
const formatRes = keysToCamelCase
147+
const formatReq = pipe(
148+
keysToPascalCase,
149+
map(ifElse(isObjectLike, keysToPascalCase, identity)),
150+
ifElse(
151+
has('Target'),
152+
mapPath(
153+
['Target'],
154+
pipe(
155+
keysToPascalCase,
156+
map(ifElse(isObjectLike, keysToPascalCase, identity))
157+
)
158+
),
159+
identity
160+
)
161+
)
162+
163+
const formatRes = pipe(
164+
keysToCamelCase,
165+
map(ifElse(isObjectLike, keysToCamelCase, identity)),
166+
ifElse(
167+
has('Target'),
168+
mapPath(
169+
['Target'],
170+
pipe(
171+
keysToCamelCase,
172+
map(ifElse(isObjectLike, keysToCamelCase, identity))
173+
)
174+
),
175+
identity
176+
)
177+
)

0 commit comments

Comments
 (0)