Skip to content

Commit 875d350

Browse files
committed
[02237] Extract ProcessInboxFileAsync helper to eliminate duplicate retry logic
1 parent 9d9f0ef commit 875d350

1 file changed

Lines changed: 35 additions & 42 deletions

File tree

src/tendril/Ivy.Tendril/Services/InboxWatcherService.cs

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -93,54 +93,23 @@ private async Task ProcessFileAsync(string filePath)
9393
if (!File.Exists(filePath))
9494
return;
9595

96-
var content = await FileHelper.ReadAllTextAsync(filePath);
97-
var (project, description, sourcePath) = ParseContent(content);
98-
99-
if (string.IsNullOrWhiteSpace(description))
96+
try
10097
{
101-
Console.Error.WriteLine($"Skipping inbox file '{filePath}' — empty description.");
102-
return;
98+
await ProcessInboxFileAsync(filePath);
10399
}
104-
105-
// Rename to .processing so the watcher/poller ignores it while the job runs
106-
var processingPath = filePath + ".processing";
107-
File.Move(filePath, processingPath);
108-
109-
var args = new List<string> { "-Description", description, "-Project", project };
110-
if (!string.IsNullOrEmpty(sourcePath))
111-
args.AddRange(["-SourcePath", sourcePath]);
112-
_jobService.StartJob("MakePlan", args.ToArray(), processingPath);
113-
}
114-
catch (Exception ex)
115-
{
116-
// Retry once after a short delay
117-
try
100+
catch (Exception ex)
118101
{
102+
// Retry once after a short delay
119103
await Task.Delay(1000);
120-
if (!File.Exists(filePath))
121-
return;
122-
123-
var content = await FileHelper.ReadAllTextAsync(filePath);
124-
var (project, description, sourcePath) = ParseContent(content);
125-
126-
if (string.IsNullOrWhiteSpace(description))
104+
try
127105
{
128-
Console.Error.WriteLine($"Skipping inbox file '{filePath}' — empty description.");
129-
return;
106+
await ProcessInboxFileAsync(filePath);
107+
}
108+
catch (Exception retryEx)
109+
{
110+
Console.Error.WriteLine(
111+
$"Failed to process inbox file '{filePath}' after retry. Initial error: {ex.Message}. Retry error: {retryEx.Message}");
130112
}
131-
132-
var processingPath = filePath + ".processing";
133-
File.Move(filePath, processingPath);
134-
135-
var args = new List<string> { "-Description", description, "-Project", project };
136-
if (!string.IsNullOrEmpty(sourcePath))
137-
args.AddRange(["-SourcePath", sourcePath]);
138-
_jobService.StartJob("MakePlan", args.ToArray(), processingPath);
139-
}
140-
catch (Exception retryEx)
141-
{
142-
Console.Error.WriteLine(
143-
$"Failed to process inbox file '{filePath}' after retry. Initial error: {ex.Message}. Retry error: {retryEx.Message}");
144113
}
145114
}
146115
finally
@@ -149,6 +118,30 @@ private async Task ProcessFileAsync(string filePath)
149118
}
150119
}
151120

121+
private async Task ProcessInboxFileAsync(string filePath)
122+
{
123+
if (!File.Exists(filePath))
124+
return;
125+
126+
var content = await FileHelper.ReadAllTextAsync(filePath);
127+
var (project, description, sourcePath) = ParseContent(content);
128+
129+
if (string.IsNullOrWhiteSpace(description))
130+
{
131+
Console.Error.WriteLine($"Skipping inbox file '{filePath}' — empty description.");
132+
return;
133+
}
134+
135+
// Rename to .processing so the watcher/poller ignores it while the job runs
136+
var processingPath = filePath + ".processing";
137+
File.Move(filePath, processingPath);
138+
139+
var args = new List<string> { "-Description", description, "-Project", project };
140+
if (!string.IsNullOrEmpty(sourcePath))
141+
args.AddRange(["-SourcePath", sourcePath]);
142+
_jobService.StartJob("MakePlan", args.ToArray(), processingPath);
143+
}
144+
152145
internal static (string project, string description, string? sourcePath) ParseContent(string content)
153146
{
154147
if (content.StartsWith("---"))

0 commit comments

Comments
 (0)