Skip to content

Commit ad0d678

Browse files
committed
Fix comments
1 parent 9d1a4fe commit ad0d678

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

agent/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ func (a *agent) run(ctx context.Context) error {
682682
} else {
683683
a.setLifecycle(ctx, codersdk.WorkspaceAgentLifecycleReady)
684684
}
685-
a.scriptRunner.StartCRON()
685+
a.scriptRunner.StartCron()
686686
})
687687
if err != nil {
688688
return xerrors.Errorf("track conn goroutine: %w", err)

agent/agentscripts/agentscripts.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ func (r *Runner) Init(ctx context.Context, scripts []codersdk.WorkspaceAgentScri
8787
return nil
8888
}
8989

90-
// StartCRON starts the cron scheduler.
90+
// StartCron starts the cron scheduler.
9191
// This is done async to allow for the caller to execute scripts prior.
92-
func (r *Runner) StartCRON() {
92+
func (r *Runner) StartCron() {
9393
r.cron.Start()
9494
}
9595

@@ -123,16 +123,16 @@ func (r *Runner) Execute(ctx context.Context, filter func(script codersdk.Worksp
123123
// If the process does not exit after a few seconds, it is forcefully killed.
124124
// This function immediately returns after a timeout, and does not wait for the process to exit.
125125
func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript) error {
126-
logger := r.Logger.With(slog.F("log_source", script.LogPath))
127-
logger.Info(ctx, "running agent script", slog.F("script", script.Script))
128-
129126
logPath := script.LogPath
130127
if logPath == "" {
131128
logPath = fmt.Sprintf("coder-%s-script.log", script.LogSourceID)
132129
}
133130
if !filepath.IsAbs(logPath) {
134131
logPath = filepath.Join(r.LogDir, logPath)
135132
}
133+
logger := r.Logger.With(slog.F("log_path", logPath))
134+
logger.Info(ctx, "running agent script", slog.F("script", script.Script))
135+
136136
fileWriter, err := r.Filesystem.OpenFile(logPath, os.O_CREATE|os.O_RDWR, 0o600)
137137
if err != nil {
138138
return xerrors.Errorf("open %s script log file: %w", logPath, err)

coderd/database/dump.sql

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/foreign_key_constraint.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000156_workspace_agent_script.up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BEGIN;
22
CREATE TABLE workspace_agent_log_sources (
3-
workspace_agent_id uuid NOT NULL,
3+
workspace_agent_id uuid NOT NULL REFERENCES workspace_agents(id) ON DELETE CASCADE,
44
id uuid NOT NULL,
55
created_at timestamptz NOT NULL,
66
display_name varchar(127) NOT NULL,

coderd/workspaceagents.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,8 @@ func convertWorkspaceAgentMetadataDesc(mds []database.WorkspaceAgentMetadatum) [
14381438

14391439
func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordinator,
14401440
dbAgent database.WorkspaceAgent, apps []codersdk.WorkspaceApp, scripts []codersdk.WorkspaceAgentScript, logSources []codersdk.WorkspaceAgentLogSource,
1441-
agentInactiveDisconnectTimeout time.Duration, agentFallbackTroubleshootingURL string) (codersdk.WorkspaceAgent, error) {
1441+
agentInactiveDisconnectTimeout time.Duration, agentFallbackTroubleshootingURL string,
1442+
) (codersdk.WorkspaceAgent, error) {
14421443
var envs map[string]string
14431444
if dbAgent.EnvironmentVariables.Valid {
14441445
err := json.Unmarshal(dbAgent.EnvironmentVariables.RawMessage, &envs)
@@ -1455,6 +1456,17 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin
14551456
subsystems[i] = codersdk.AgentSubsystem(subsystem)
14561457
}
14571458

1459+
legacyStartupScriptBehavior := codersdk.WorkspaceAgentStartupScriptBehaviorNonBlocking
1460+
for _, script := range scripts {
1461+
if !script.RunOnStart {
1462+
continue
1463+
}
1464+
if !script.StartBlocksLogin {
1465+
continue
1466+
}
1467+
legacyStartupScriptBehavior = codersdk.WorkspaceAgentStartupScriptBehaviorBlocking
1468+
}
1469+
14581470
workspaceAgent := codersdk.WorkspaceAgent{
14591471
ID: dbAgent.ID,
14601472
CreatedAt: dbAgent.CreatedAt,
@@ -1465,7 +1477,7 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin
14651477
Architecture: dbAgent.Architecture,
14661478
OperatingSystem: dbAgent.OperatingSystem,
14671479
Scripts: scripts,
1468-
StartupScriptBehavior: codersdk.WorkspaceAgentStartupScriptBehaviorNonBlocking,
1480+
StartupScriptBehavior: legacyStartupScriptBehavior,
14691481
LogsLength: dbAgent.LogsLength,
14701482
LogsOverflowed: dbAgent.LogsOverflowed,
14711483
LogSources: logSources,

0 commit comments

Comments
 (0)