Skip to content

Commit

Permalink
core,script: ensure that output is captured during script setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdanp committed Nov 4, 2023
1 parent cf3e531 commit 9c4820a
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions core/script.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,20 @@
(define-rpc (apply-script [_ script : String]
[to-records records : (Listof IteratorRecord)]
[in-workspace id : UVarint] : ApplyResult)
(define script-tbl (make-script 'apply-script script))
(define output
(open-output-bytes))
(define-values (result items)
(parameterize ([current-output-port output]
[current-error-port output])
(do-apply-script script records)))
(ApplyResult
(reverse items)
(get-output-bytes output)
(->ReduceResult result)))

(define (do-apply-script script records)
(define script-tbl
(make-script 'apply-script script))
(define transform-proc (table-ref script-tbl #"transform"))
(unless (procedure? transform-proc)
(error 'apply-script "script.transform is not a procedure"))
Expand All @@ -179,25 +192,17 @@
(cond
[(nil? render-proc) s]
[else (render-proc s)]))
(define output (open-output-bytes))
(define-values (result items)
(parameterize ([current-output-port output]
[current-error-port output])
(define-values (state items)
(for*/fold ([s nil] [items null])
([r (in-list records)]
[t (in-value (transform r))]
#:unless (nil? t))
(define item
(IteratorResult.transformed (table->IteratorRecord t) r))
(values
(reduce t s)
(cons item items))))
(values (render state) items)))
(ApplyResult
(reverse items)
(get-output-bytes output)
(->ReduceResult result)))
(define-values (state items)
(for*/fold ([s nil] [items null])
([r (in-list records)]
[t (in-value (transform r))]
#:unless (nil? t))
(define item
(IteratorResult.transformed (table->IteratorRecord t) r))
(values
(reduce t s)
(cons item items))))
(values (render state) items))

(define-rpc (deactivate-script [for-topic topic : String]
[in-workspace id : UVarint])
Expand Down

0 comments on commit 9c4820a

Please sign in to comment.