|
| 1 | +# Copyright 2024 SiFive, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You should have received a copy of LICENSE.Apache2 along with |
| 6 | +# this software. If not, you may obtain a copy at |
| 7 | +# |
| 8 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +package wake |
| 17 | + |
| 18 | +# rscRunner: Creates a remote cache runner for a given api config |
| 19 | +# |
| 20 | +# ``` |
| 21 | +# rscRunner (RemoteCacheApi "local" 1234 "auth") = (Runner ...) |
| 22 | +# ``` |
| 23 | +export target rscRunner (rscApi: RemoteCacheApi): Runner = |
| 24 | + mkRemoteCacheRunner rscApi (\_ Pass "") "/workspace" fuseRunner |
| 25 | + |
| 26 | +# mkRemoteCacheRunner: Creates a remote cache runner from an underlying runner |
| 27 | +# |
| 28 | +# - `rscApi`: the remote cache to connect to |
| 29 | +# - `hashFn`: a runner provided hash, used to invalate jobs that match by key but not by something |
| 30 | +# known only to the runner |
| 31 | +# - `wakeroot`: Absolute path to the root of the wake project |
| 32 | +# - `baseRunner`: The runner that should be used for a cache miss |
| 33 | +# ``` |
| 34 | +# mkRemoteCacheRunner (RemoteCacheApi ...) (\_ Pass "") "" baseRunner = (Runner ...) |
| 35 | +# ``` |
| 36 | +export def mkRemoteCacheRunner (_rscApi: RemoteCacheApi) (_hashFn: Result RunnerInput Error => Result String Error) (_wakeroot: String) ((Runner name score baseDoIt): Runner): Runner = |
| 37 | + def badlaunch job error = prim "job_fail_launch" |
| 38 | + |
| 39 | + def doit job runnerInput = match runnerInput |
| 40 | + Fail e -> |
| 41 | + def _ = badlaunch job e |
| 42 | + |
| 43 | + Fail e |
| 44 | + Pass input -> |
| 45 | + # TODO: Search the cache for the job |
| 46 | + |
| 47 | + # Run the job to get the results |
| 48 | + require Pass output = baseDoIt job (Pass input) |
| 49 | + |
| 50 | + # TODO: Insert the job into the cache |
| 51 | + |
| 52 | + Pass output |
| 53 | + |
| 54 | + Runner "remote-cache: {name}" score doit |
| 55 | + |
0 commit comments