This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
483 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using Microsoft.Azure.Functions.Worker; | ||
|
||
namespace Microsoft.OneFuzz.Service; | ||
|
||
|
||
public class TimerTasks | ||
{ | ||
private readonly ILogTracer _logger; | ||
|
||
|
||
private readonly ITaskOperations _taskOperations; | ||
|
||
private readonly IJobOperations _jobOperations; | ||
|
||
private readonly IScheduler _scheduler; | ||
|
||
|
||
public TimerTasks(ILogTracer logger, ITaskOperations taskOperations, IJobOperations jobOperations, IScheduler scheduler) | ||
{ | ||
_logger = logger; | ||
_taskOperations = taskOperations; | ||
_jobOperations = jobOperations; | ||
_scheduler = scheduler; | ||
} | ||
|
||
//[Function("TimerTasks")] | ||
public async Async.Task Run([TimerTrigger("1.00:00:00")] TimerInfo myTimer) | ||
{ | ||
var expriredTasks = _taskOperations.SearchExpired(); | ||
await foreach (var task in expriredTasks) | ||
{ | ||
_logger.Info($"stopping expired task. job_id:{task.JobId} task_id:{task.TaskId}"); | ||
await _taskOperations.MarkStopping(task); | ||
} | ||
|
||
|
||
var expiredJobs = _jobOperations.SearchExpired(); | ||
|
||
await foreach (var job in expiredJobs) | ||
{ | ||
_logger.Info($"stopping expired job. job_id:{job.JobId }"); | ||
await _jobOperations.Stopping(job); | ||
} | ||
|
||
var jobs = _jobOperations.SearchState(states: JobStateHelper.NeedsWork); | ||
|
||
await foreach (var job in jobs) | ||
{ | ||
_logger.Info($"update job: {job.JobId}"); | ||
await _jobOperations.ProcessStateUpdates(job); | ||
} | ||
|
||
var tasks = _taskOperations.SearchStates(states: TaskStateHelper.NeedsWork()); | ||
await foreach (var task in tasks) | ||
{ | ||
_logger.Info($"update task: {task.TaskId}"); | ||
await _taskOperations.ProcessStateUpdate(task); | ||
} | ||
|
||
await _scheduler.ScheduleTasks(); | ||
|
||
await _jobOperations.StopNeverStartedJobs(); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.