Skip to content

Commit

Permalink
feat(context): upgrade to grab logger from context
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Dec 27, 2024
1 parent d0ecde8 commit f3b1e30
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 78 deletions.
127 changes: 104 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"change-case": "4.1.2",
"date-fns": "2.30.0",
"simple-in-memory-queue": "1.1.7",
"uuid": "9.0.0"
"uuid": "9.0.0",
"visualogic": "1.3.2"
},
"peerDependencies": {
"type-fns": "^1.13.0"
Expand Down Expand Up @@ -90,7 +91,6 @@
"husky": "8.0.3",
"jest": "29.3.1",
"prettier": "2.8.1",
"simple-leveled-log-methods": "0.3.0",
"test-fns": "1.3.0",
"ts-jest": "29.1.3",
"ts-node": "10.9.2",
Expand Down
6 changes: 2 additions & 4 deletions src/logic/withAsyncTaskExecutionLifecycleEnqueue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ describe('withAsyncTaskExecutionLifecycleQueue', () => {
const enqueue = withAsyncTaskExecutionLifecycleEnqueue({
getNew: exampleGetNew,
dao: exampleDao,
log: console,
queue,
});

then('it should successfully allow enqueue', async () => {
const enqueued = await enqueue({});
const enqueued = await enqueue({}, { log: console });
expect(enqueued).toHaveProperty('status');
expect(enqueued.status).toEqual(AsyncTaskStatus.QUEUED);
});
Expand All @@ -76,12 +75,11 @@ describe('withAsyncTaskExecutionLifecycleQueue', () => {
const enqueue = withAsyncTaskExecutionLifecycleEnqueue({
getNew: exampleGetNew,
dao: exampleDao,
log: console,
queue,
});

then('it should successfully allow enqueue', async () => {
const enqueued = await enqueue({});
const enqueued = await enqueue({}, { log: console });
expect(enqueued).toHaveProperty('status');
expect(enqueued.status).toEqual(AsyncTaskStatus.QUEUED);
});
Expand Down
18 changes: 8 additions & 10 deletions src/logic/withAsyncTaskExecutionLifecycleEnqueue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UnexpectedCodePathError } from '@ehmpathy/error-fns';
import type { LogMethods } from 'simple-leveled-log-methods';
import { HasMetadata, isAFunction } from 'type-fns';
import { VisualogicContext } from 'visualogic';

import { uuid } from '../deps';
import {
Expand Down Expand Up @@ -96,17 +96,15 @@ export const withAsyncTaskExecutionLifecycleEnqueue = <
T extends AsyncTask,
U extends Partial<T>,
M extends Partial<T> & { status: AsyncTaskStatus },
C extends AsyncTaskDaoContext,
C extends AsyncTaskDaoContext & VisualogicContext,
I extends U,
>({
getNew,
dao,
log,
queue,
}: {
getNew: (input: I, context: C) => T | Promise<T>;
dao: AsyncTaskDao<T, U, M, C>;
log: LogMethods;
queue: SimpleAsyncTaskSqsQueueContract | SimpleAsyncTaskAnyQueueContract<T>;
}) => {
return async (input: I, context: C): Promise<HasMetadata<T>> => {
Expand All @@ -120,7 +118,7 @@ export const withAsyncTaskExecutionLifecycleEnqueue = <

// if the task already exists, check that its in a queueable state
if (taskFound?.status === AsyncTaskStatus.QUEUED) {
log.debug(
context.log.debug(
'enqueueTask.progress: skipped adding task to queue. reason: task is already queued',
{
task: taskFound,
Expand All @@ -129,7 +127,7 @@ export const withAsyncTaskExecutionLifecycleEnqueue = <
return taskFound; // if already queued, no need to duplicate the request
}
if (taskFound?.status === AsyncTaskStatus.ATTEMPTED) {
log.debug(
context.log.debug(
'enqueueTask.progress: skipped adding task to queue. reason: task is already being attempted from queue',
{
task: taskFound,
Expand All @@ -138,7 +136,7 @@ export const withAsyncTaskExecutionLifecycleEnqueue = <
return taskFound; // if already being attempted, no need to duplicate the request
}
if (taskFound?.status === AsyncTaskStatus.FULFILLED) {
log.debug(
context.log.debug(
'enqueueTask.progress: skipped adding task to queue. reason: task was already fulfilled',
{
task: taskFound,
Expand All @@ -147,7 +145,7 @@ export const withAsyncTaskExecutionLifecycleEnqueue = <
return taskFound; // if already fulfilled, no sense in trying it again
}
if (taskFound?.status === AsyncTaskStatus.CANCELED) {
log.debug(
context.log.debug(
'enqueueTask.progress: skipped adding task to queue. reason: task was already canceled',
{
task: taskFound,
Expand All @@ -164,7 +162,7 @@ export const withAsyncTaskExecutionLifecycleEnqueue = <
...taskReadyToQueue,
status: AsyncTaskStatus.QUEUED,
};
log.debug('enqueueTask.progress: adding task to queue', {
context.log.debug('enqueueTask.progress: adding task to queue', {
task: taskToQueue,
queue: { type: queue.type },
});
Expand Down Expand Up @@ -196,7 +194,7 @@ export const withAsyncTaskExecutionLifecycleEnqueue = <
{ queue },
);
})();
log.debug('enqueueTask.progress: added task to queue', {
context.log.debug('enqueueTask.progress: added task to queue', {
task: taskToQueue,
queue: { type: queue.type },
});
Expand Down
Loading

0 comments on commit f3b1e30

Please sign in to comment.