mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
fix: send job outputs & job result to Forgejo in sync with each other (#995)
Fixes #994. First commit ensures that the interpolateResults method is invoked before data is sent to the reporter. Second commit changes how data is sent to the reporter to include both the result and the job outputs. <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/995): <!--number 995 --><!--line 0 --><!--description Zml4OiBzZW5kIGpvYiBvdXRwdXRzICYgam9iIHJlc3VsdCB0byBGb3JnZWpvIGluIHN5bmMgd2l0aCBlYWNoIG90aGVy-->fix: send job outputs & job result to Forgejo in sync with each other<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/995 Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
This commit is contained in:
parent
3585d67743
commit
2573ccaf19
6 changed files with 374 additions and 51 deletions
|
@ -130,6 +130,11 @@ func (r *Reporter) Fire(entry *log.Entry) error {
|
|||
}
|
||||
}
|
||||
}
|
||||
if v, ok := entry.Data["jobOutputs"]; ok {
|
||||
_ = r.setOutputs(v.(map[string]string))
|
||||
} else {
|
||||
log.Panicf("received log entry with jobResult, but without jobOutputs -- outputs will be corrupted for this job")
|
||||
}
|
||||
}
|
||||
if !r.duringSteps() {
|
||||
r.logRows = appendIfNotNil(r.logRows, r.parseLogRow(entry))
|
||||
|
@ -209,7 +214,7 @@ func (r *Reporter) logf(format string, a ...any) {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *Reporter) GetOutputs() map[string]string {
|
||||
func (r *Reporter) cloneOutputs() map[string]string {
|
||||
outputs := make(map[string]string)
|
||||
r.outputs.Range(func(k, v any) bool {
|
||||
if val, ok := v.(string); ok {
|
||||
|
@ -220,10 +225,9 @@ func (r *Reporter) GetOutputs() map[string]string {
|
|||
return outputs
|
||||
}
|
||||
|
||||
func (r *Reporter) SetOutputs(outputs map[string]string) error {
|
||||
r.stateMu.Lock()
|
||||
defer r.stateMu.Unlock()
|
||||
|
||||
// Errors from setOutputs are logged into the reporter automatically; the `errors` return value is only used for unit
|
||||
// tests.
|
||||
func (r *Reporter) setOutputs(outputs map[string]string) error {
|
||||
var errs []error
|
||||
recordError := func(format string, a ...any) {
|
||||
r.logf(format, a...)
|
||||
|
@ -369,10 +373,9 @@ func (r *Reporter) ReportState() error {
|
|||
|
||||
r.stateMu.RLock()
|
||||
state := proto.Clone(r.state).(*runnerv1.TaskState)
|
||||
outputs := r.cloneOutputs()
|
||||
r.stateMu.RUnlock()
|
||||
|
||||
outputs := r.GetOutputs()
|
||||
|
||||
resp, err := r.client.UpdateTask(r.ctx, connect.NewRequest(&runnerv1.UpdateTaskRequest{
|
||||
State: state,
|
||||
Outputs: outputs,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue