Skip to content

Commit f106ed8

Browse files
committed
Added cron
1 parent ea46960 commit f106ed8

10 files changed

Lines changed: 610 additions & 58 deletions

src/LabSync.Core/Entities/ScheduledScript.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ScheduledScript(
4040
string name,
4141
string scriptContent,
4242
ScriptInterpreterType interpreterType,
43-
string[] arguments,
43+
string[]? arguments,
4444
int timeoutSeconds,
4545
string? cronExpression,
4646
DateTimeOffset? runAt,
@@ -52,7 +52,7 @@ public ScheduledScript(
5252
Name = name;
5353
ScriptContent = scriptContent;
5454
InterpreterType = interpreterType;
55-
Arguments = arguments;
55+
Arguments = arguments ?? [];
5656
TimeoutSeconds = timeoutSeconds;
5757
CronExpression = cronExpression;
5858
RunAt = runAt;
@@ -66,7 +66,7 @@ public void Update(
6666
string name,
6767
string scriptContent,
6868
ScriptInterpreterType interpreterType,
69-
string[] arguments,
69+
string[]? arguments,
7070
int timeoutSeconds,
7171
string? cronExpression,
7272
DateTimeOffset? runAt,
@@ -76,7 +76,7 @@ public void Update(
7676
Name = name;
7777
ScriptContent = scriptContent;
7878
InterpreterType = interpreterType;
79-
Arguments = arguments;
79+
Arguments = arguments ?? [];
8080
TimeoutSeconds = timeoutSeconds;
8181
CronExpression = cronExpression;
8282
RunAt = runAt;

src/LabSync.Server/Controllers/ScriptSchedulerController.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ public class ScriptSchedulerController(ScheduledScriptService schedulerService)
1313
[HttpPost]
1414
public async Task<ActionResult<ScheduledScriptDto>> Create([FromBody] CreateScheduledScriptDto dto)
1515
{
16-
var result = await schedulerService.CreateAsync(dto, User.Identity?.Name);
17-
return CreatedAtAction(nameof(GetById), new { id = result.Id }, result);
16+
try
17+
{
18+
var result = await schedulerService.CreateAsync(dto, User.Identity?.Name);
19+
return Ok(result);
20+
}
21+
catch (Exception ex)
22+
{
23+
return StatusCode(500, new { message = ex.Message, detail = ex.InnerException?.Message, stackTrace = ex.StackTrace });
24+
}
1825
}
1926

2027
[HttpPut("{id}")]

src/LabSync.Server/Data/Configurations/ScheduledScriptConfiguration.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ public void Configure(EntityTypeBuilder<ScheduledScript> builder)
2222

2323
builder.Property(s => s.Arguments)
2424
.IsRequired()
25-
.HasColumnType("text[]");
25+
.HasColumnType("text")
26+
.HasConversion(
27+
v => string.Join(';', v),
28+
v => v.Split(';', StringSplitOptions.RemoveEmptyEntries),
29+
new Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer<string[]>(
30+
(c1, c2) => c1 != null && c2 != null && c1.SequenceEqual(c2),
31+
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
32+
c => c.ToArray()));
2633

2734
builder.Property(s => s.CronExpression)
2835
.HasMaxLength(100);

0 commit comments

Comments
 (0)