* Added method to Delete task
* Added WorkingDirectory to RunProcess method
This commit is contained in:
@@ -83,6 +83,21 @@ public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager
|
||||
return Ok("Zadanie zostało dodane.");
|
||||
}
|
||||
|
||||
[HttpPost("DeleteTask")]
|
||||
public async Task<IActionResult> DeleteTask([FromBody] TaskSchedulerDto taskSchedulerDto)
|
||||
{
|
||||
int result = await service.DeleteTaskScheduler(taskSchedulerDto.RowPointer);
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
return BadRequest("Nie udało się usunąć zadania.");
|
||||
}
|
||||
|
||||
recurringJobManager.RemoveIfExists(taskSchedulerDto.Name);
|
||||
|
||||
return Ok("Zadanie zostało usunięte.");
|
||||
}
|
||||
|
||||
[HttpGet("GetTasks")]
|
||||
public async Task<ActionResult<IEnumerable<TaskSchedulerDto>>> GetTasks()
|
||||
{
|
||||
@@ -117,7 +132,8 @@ public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true
|
||||
CreateNoWindow = true,
|
||||
WorkingDirectory = Path.GetDirectoryName(pathToApp)
|
||||
}
|
||||
};
|
||||
process.Start();
|
||||
|
||||
@@ -18,14 +18,17 @@
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<SfGrid DataSource="@Tasks" AllowPaging="true">
|
||||
<SfGrid DataSource="@Tasks" AllowPaging="true" ShowColumnMenu="true" Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })">
|
||||
<GridColumns>
|
||||
<GridColumn Field=@nameof(TaskSchedulerDto.RowPointer) IsPrimaryKey="true" HeaderText="Id"></GridColumn>
|
||||
<GridColumn Field=@nameof(TaskSchedulerDto.Name) HeaderText="Nazwa"></GridColumn>
|
||||
<GridColumn Field=@nameof(TaskSchedulerDto.Path) HeaderText="Ścieżka"></GridColumn>
|
||||
<GridColumn Field=@nameof(TaskSchedulerDto.CronOptions) HeaderText="CRON"></GridColumn>
|
||||
<GridColumn Field=@nameof(TaskSchedulerDto.LastExecution) HeaderText="Ostatnie Uruchomienie"></GridColumn>
|
||||
<GridColumn Field=@nameof(TaskSchedulerDto.NextExecution) HeaderText="Następne Uruchomienie"></GridColumn>
|
||||
</GridColumns>
|
||||
<GridEditSettings AllowDeleting="true" ShowDeleteConfirmDialog="true"></GridEditSettings>
|
||||
<GridEvents OnActionBegin="OnActionBegin" TValue="TaskSchedulerDto"></GridEvents>
|
||||
</SfGrid>
|
||||
|
||||
@code {
|
||||
@@ -37,13 +40,22 @@
|
||||
await LoadTasks();
|
||||
}
|
||||
|
||||
public async Task OnActionBegin(ActionEventArgs<TaskSchedulerDto> args)
|
||||
{
|
||||
if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Delete))
|
||||
{
|
||||
await HangfireService.DeleteTaskSchedulerAsync(args.Data);
|
||||
await LoadTasks();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AddTask()
|
||||
{
|
||||
var response = await HangfireService.AddTaskSchedulerAsync(NewTask);
|
||||
if (response == 1)
|
||||
{
|
||||
NewTask = new TaskSchedulerDto(); // Reset form
|
||||
await LoadTasks(); // Refresh list
|
||||
NewTask = new TaskSchedulerDto();
|
||||
await LoadTasks();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,4 +19,10 @@ public class HangfireService(HttpClient httpClient)
|
||||
HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync("api/HangfireJobs/AddTask", taskSchedulerDto);
|
||||
return responseMessage.IsSuccessStatusCode ? 1 : 0;
|
||||
}
|
||||
|
||||
public async Task<int> DeleteTaskSchedulerAsync(TaskSchedulerDto taskSchedulerDto)
|
||||
{
|
||||
HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync("api/HangfireJobs/DeleteTask", taskSchedulerDto);
|
||||
return responseMessage.IsSuccessStatusCode ? 1 : 0;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace OrdersManagementDataModel.Dtos;
|
||||
public class TaskSchedulerDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Guid RowPointer { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string CronOptions { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user