(name: "stdout" | "stderr", value: Uint8Array)
| 88 | } |
| 89 | |
| 90 | append(name: "stdout" | "stderr", value: Uint8Array): number { |
| 91 | const meta = this.meta(); |
| 92 | if (meta === undefined) throw new Error(`log ${this.id}: append after dispose`); |
| 93 | if (meta.exited_at !== null) throw new Error(`log ${this.id}: append after exit`); |
| 94 | const seq = this.nextSeq++; |
| 95 | if (meta.evicted === 1) { |
| 96 | // Silently drop. The live stream already got the bytes; |
| 97 | // we just can't replay them. Keep the seq counter |
| 98 | // advancing so the live stream's seq numbering stays |
| 99 | // monotonic and gap-free. |
| 100 | return seq; |
| 101 | } |
| 102 | const kind = name === "stdout" ? KIND_STDOUT : KIND_STDERR; |
| 103 | const ts = this.opts.now(); |
| 104 | const newBytes = meta.bytes + value.byteLength; |
| 105 | if (newBytes > this.opts.maxBytes) { |
| 106 | this.evict(); |
| 107 | return seq; |
| 108 | } |
| 109 | this.db.transactionSync(() => { |
| 110 | this.db.run( |
| 111 | `INSERT INTO computerd_exec_log (exec_id, seq, ts, kind, value) VALUES (?, ?, ?, ?, ?)`, |
| 112 | this.id, |
| 113 | seq, |
| 114 | ts, |
| 115 | kind, |
| 116 | value, |
| 117 | ); |
| 118 | this.db.run(`UPDATE computerd_exec_meta SET bytes = ? WHERE exec_id = ?`, newBytes, this.id); |
| 119 | }); |
| 120 | return seq; |
| 121 | } |
| 122 | |
| 123 | // Advance the seq counter and return the next value without writing |
| 124 | // any row to the database. Used for events that the runner emits on |
nothing calls this directly
no test coverage detected