gets from variant from db if stored. stores if not.
(
host: Host,
ti: TaskInfo,
opts: { forRun: boolean; aspawnOptions?: AspawnOptions; create?: boolean },
)
| 42 | |
| 43 | /** gets from variant from db if stored. stores if not. */ |
| 44 | async getTaskSetupData( |
| 45 | host: Host, |
| 46 | ti: TaskInfo, |
| 47 | opts: { forRun: boolean; aspawnOptions?: AspawnOptions; create?: boolean }, |
| 48 | ): Promise<TaskSetupData> { |
| 49 | if (!opts?.forRun) { |
| 50 | // TODO(maksym): Cache plain `viv task start` task setup datas too. |
| 51 | return this.getTaskSetupDataRaw(host, ti, opts) |
| 52 | } |
| 53 | |
| 54 | const commitOrSourceHash = ti.source.type === 'gitRepo' ? ti.source.commitId : hashTaskOrAgentSource(ti.source) |
| 55 | const stored = await this.dbTaskEnvironments.getTaskSetupData(ti.id, commitOrSourceHash) |
| 56 | if (stored != null) { |
| 57 | return stored |
| 58 | } else if (!(opts.create ?? true)) { |
| 59 | throw new TaskSetupDataNotFoundError( |
| 60 | `Task setup data not found for ${ti.id} with commit or source hash ${commitOrSourceHash}`, |
| 61 | ) |
| 62 | } |
| 63 | |
| 64 | const taskSetupData = await this.getTaskSetupDataRaw(host, ti, opts) |
| 65 | await this.dbTaskEnvironments.insertTaskSetupData(ti.id, commitOrSourceHash, taskSetupData) |
| 66 | return taskSetupData |
| 67 | } |
| 68 | |
| 69 | async getTaskInstructions(host: Host, ti: TaskInfo, opts: { forRun: boolean }): Promise<TaskInstructions> { |
| 70 | const taskSetupData = await this.getTaskSetupData(host, ti, opts) |
no test coverage detected