Skip to content

Commit 5cd364e

Browse files
authored
refactor: move article flow tasks to shared directory and update imports (#566)
# Reorganize Article Flow Structure for Better Maintainability This PR reorganizes the article flow implementation to improve code organization and maintainability: - Moved task files from `functions/article_flow_worker/tasks/` to a centralized `tasks/` directory at the project root - Created a new `flows/` directory to house flow definitions separately from worker implementations - Renamed `ArticleFlow` export to use named exports for consistency - Updated import paths in all affected files to reflect the new structure - Added a new index.ts file in the tasks directory to provide centralized exports - Added a deno.lock file for better dependency management - Included a database migration for pgflow to support flow input column These changes separate the flow definition from its worker implementation, making it easier to maintain and test each component independently while providing a clearer project structure.
1 parent e5582ae commit 5cd364e

15 files changed

Lines changed: 358 additions & 37 deletions

apps/demo/supabase/functions/article_flow_worker/article_flow.ts renamed to apps/demo/supabase/flows/article_flow.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Flow } from '@pgflow/dsl';
2-
import { fetchArticle } from './tasks/fetch-article.ts';
3-
import { summarizeArticle } from './tasks/summarize-article.ts';
4-
import { extractKeywords } from './tasks/extract-keywords.ts';
5-
import { publishArticle } from './tasks/publish-article.ts';
2+
import { fetchArticle } from '../tasks/fetch-article.ts';
3+
import { summarizeArticle } from '../tasks/summarize-article.ts';
4+
import { extractKeywords } from '../tasks/extract-keywords.ts';
5+
import { publishArticle } from '../tasks/publish-article.ts';
66

77
const SLEEP_MS = 1000;
88

@@ -12,7 +12,7 @@ function sleep(ms: number) {
1212
}
1313

1414
// Flow definition - clean and minimal
15-
export default new Flow<{ url: string }>({
15+
export const ArticleFlow = new Flow<{ url: string }>({
1616
slug: 'article_flow',
1717
baseDelay: 1,
1818
maxAttempts: 2

apps/demo/supabase/flows/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
// Re-export all flows from this directory
2-
// Example: export { MyFlow } from './my-flow.ts';
2+
3+
export { ArticleFlow } from './article_flow.ts';

apps/demo/supabase/functions/article_flow_worker/deno.lock

Lines changed: 156 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { EdgeWorker } from '@pgflow/edge-worker';
2-
import ArticleFlow from './article_flow.ts';
2+
import { ArticleFlow } from '../../flows/article_flow.ts';
33

44
EdgeWorker.start(ArticleFlow, { maxPollSeconds: 5, pollIntervalMs: 100 });

apps/demo/supabase/functions/article_flow_worker/tests/extract-keywords.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assert } from 'https://deno.land/std@0.208.0/assert/mod.ts';
2-
import { extractKeywords } from '../tasks/extract-keywords.ts';
2+
import { extractKeywords } from '../../../tasks/extract-keywords.ts';
33
import { load } from 'https://deno.land/std@0.208.0/dotenv/mod.ts';
44

55
// Load environment variables from .env file if it exists

apps/demo/supabase/functions/article_flow_worker/tests/fetch-article.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assert } from 'https://deno.land/std@0.208.0/assert/mod.ts';
22
import { stub } from 'https://deno.land/std@0.208.0/testing/mock.ts';
3-
import { fetchArticle } from '../tasks/fetch-article.ts';
3+
import { fetchArticle } from '../../../tasks/fetch-article.ts';
44
import { load } from 'https://deno.land/std@0.208.0/dotenv/mod.ts';
55

66
// Load environment variables from .env file if it exists

apps/demo/supabase/functions/article_flow_worker/tests/publish-article.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assertEquals, assert } from 'https://deno.land/std@0.208.0/assert/mod.ts';
2-
import { publishArticle } from '../tasks/publish-article.ts';
2+
import { publishArticle } from '../../../tasks/publish-article.ts';
33

44
Deno.test('publishArticle - generates article ID and timestamp', () => {
55
const summary = 'Test summary';

apps/demo/supabase/functions/article_flow_worker/tests/summarize-article.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assert, assertRejects } from 'https://deno.land/std@0.208.0/assert/mod.ts';
2-
import { summarizeArticle } from '../tasks/summarize-article.ts';
2+
import { summarizeArticle } from '../../../tasks/summarize-article.ts';
33
import { load } from 'https://deno.land/std@0.208.0/dotenv/mod.ts';
44

55
// Load environment variables from .env file if it exists

0 commit comments

Comments
 (0)