-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sqs): expose utility to get sqs queue url from task name
- Loading branch information
1 parent
c6ef64c
commit 034a3b4
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { DomainEntity } from 'domain-objects'; | ||
|
||
import { AsyncTask, AsyncTaskStatus } from '../../domain/objects/AsyncTask'; | ||
import { getSqsQueueUrlForTask } from './getSqsQueueUrlForTask'; | ||
|
||
/** | ||
* an async task for emitting some data to remote persistance | ||
* | ||
* e.g., for @mhetrics/app-usage-events-react | ||
*/ | ||
interface AsyncTaskEmitToRemote extends AsyncTask { | ||
uuid?: string; | ||
updatedAt?: string; | ||
status: AsyncTaskStatus; | ||
endpoint: string; | ||
bytes: number; | ||
payload: string; | ||
} | ||
class AsyncTaskEmitToRemote | ||
extends DomainEntity<AsyncTaskEmitToRemote> | ||
implements AsyncTaskEmitToRemote {} | ||
|
||
describe('getSqsQueueUrlForTask', () => { | ||
it('should define queue url accurately based on config and task name', async () => { | ||
const url = await getSqsQueueUrlForTask(AsyncTaskEmitToRemote, { | ||
config: { | ||
aws: { | ||
account: '__account_id__', | ||
}, | ||
project: 'svc-doitall', | ||
environment: { | ||
access: 'prod', | ||
}, | ||
}, | ||
}); | ||
expect(url).toEqual( | ||
'https://sqs.us-east-1.amazonaws.com/__account_id__/svc-doitall-prod-async-task-emit-to-remote-llq', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { paramCase } from 'change-case'; | ||
import type { DomainObject } from 'domain-objects'; | ||
|
||
import { AsyncTask } from '../../domain/objects/AsyncTask'; | ||
|
||
export type ClassOf<T> = new (...args: any[]) => T; | ||
|
||
export const getSqsQueueUrlForTask = async ( | ||
input: ClassOf<DomainObject<AsyncTask>>, | ||
context: { | ||
config: { | ||
aws: { | ||
account: string; | ||
}; | ||
project: string; | ||
environment: { | ||
access: 'prod' | 'dev' | 'test'; | ||
}; | ||
}; | ||
}, | ||
) => { | ||
const taskName = input.name; | ||
return [ | ||
'https://sqs.us-east-1.amazonaws.com', | ||
`/${context.config.aws.account}/`, | ||
`${context.config.project}-${context.config.environment.access}-${paramCase( | ||
taskName, | ||
)}-llq`, | ||
].join(''); | ||
}; |