Skip to content

Commit

Permalink
Fix scheduler create
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Jun 9, 2024
1 parent ee329ea commit e2eb2fc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
16 changes: 14 additions & 2 deletions examples/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@ import { SchedulerClient } from '../index.js'

export const createSchedule =
({ log }) =>
async (scheduleName) => {
async (scheduleName, arn, roleArn) => {
const client = new SchedulerClient({
log
})
return client.createSchedule(scheduleName, {})
return client.createSchedule(scheduleName, {
scheduleExpression: 'rate(1 minute)',
flexibleTimeWindow: { mode: 'OFF' },
input: { foo: 'bar' },
target: {
arn,
roleArn,
eventBridgeParameters: {
detailType: 'example',
source: 'example'
}
}
})
}

export const deleteSchedule =
Expand Down
43 changes: 41 additions & 2 deletions lib/clients/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import {
} from '@aws-sdk/client-scheduler'
import { v4 as uuidv4 } from 'uuid'
import { createLogger } from '@meltwater/mlabs-logger'
import {
has,
identity,
ifElse,
isObjLike,
isObjectLike,
map,
mapPath,
pipe
} from '@meltwater/phi'

import { createCache } from '../cache.js'
import { keysToCamelCase, keysToPascalCase } from '../case.js'
Expand Down Expand Up @@ -134,5 +144,34 @@ export class SchedulerClient {
}
}

const formatReq = keysToPascalCase
const formatRes = keysToCamelCase
const formatReq = pipe(
keysToPascalCase,
map(ifElse(isObjectLike, keysToPascalCase, identity)),
ifElse(
has('Target'),
mapPath(
['Target'],
pipe(
keysToPascalCase,
map(ifElse(isObjectLike, keysToPascalCase, identity))
)
),
identity
)
)

const formatRes = pipe(
keysToCamelCase,
map(ifElse(isObjectLike, keysToCamelCase, identity)),
ifElse(
has('Target'),
mapPath(
['Target'],
pipe(
keysToCamelCase,
map(ifElse(isObjectLike, keysToCamelCase, identity))
)
),
identity
)
)

0 comments on commit e2eb2fc

Please sign in to comment.