Skip to content

Commit

Permalink
Add force of _tasks creation by knob (#4236)
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinTyukalov authored Apr 21, 2023
1 parent 240cd92 commit e54db88
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Agent.Sdk/Knob/AgentKnobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,5 +444,12 @@ public class AgentKnobs
"Forces the agent to fetch list of .NET 6 supporting systems from server",
new EnvironmentKnobSource("AGENT_ENABLE_FETCHING_NET6_LIST"),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob ForceCreateTasksDirectory = new Knob(
nameof(ForceCreateTasksDirectory),
"Forces the agent to create _tasks folder for tasks.",
new RuntimeKnobSource("AGENT_FORCE_CREATE_TASKS_DIRECTORY"),
new EnvironmentKnobSource("AGENT_FORCE_CREATE_TASKS_DIRECTORY"),
new BuiltInDefaultKnobSource("false"));
}
}
19 changes: 18 additions & 1 deletion src/Agent.Worker/JobExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel
Trace.Info($"Run initial step from extension {this.GetType().Name}.");
InitializeJobExtension(context, message?.Steps, message?.Workspace);

if (AgentKnobs.ForceCreateTasksDirectory.GetValue(context).AsBoolean())
{
var tasksDir = HostContext.GetDirectory(WellKnownDirectory.Tasks);
try
{
Trace.Info($"Pre-creating {tasksDir} directory");
Directory.CreateDirectory(tasksDir);
IOUtil.ValidateExecutePermission(tasksDir);
}
catch (Exception ex)
{
Trace.Error(ex);
context.Error(ex);
}
}

// Download tasks if not already in the cache
Trace.Info("Downloading task definitions.");
var taskManager = HostContext.GetService<ITaskManager>();
Expand Down Expand Up @@ -639,7 +655,8 @@ private void OutputSetupInfo(IExecutionContext context)
}
}

public class UnsupportedOsException : Exception {
public class UnsupportedOsException : Exception
{
public UnsupportedOsException(string message) : base(message) { }
}
}

0 comments on commit e54db88

Please sign in to comment.