1import * as GCP from "@/GCP";
2import * as Effect from "effect/Effect";
3import { serveProbes } from "../../bindingHost.ts";
4
5/** Scheduled query the host starts runs of (roles/bigquery.admin, project). */
6export const Nightly = Effect.gen(function* () {
7 const dataset = yield* GCP.BigQuery.Dataset("Analytics", {
8 location: "US-CENTRAL1",
9 forceDestroy: true,
10 });
11 return yield* GCP.BigQueryDataTransfer.TransferConfig("Nightly", {
12 location: "us-central1",
13 dataSourceId: "scheduled_query",
14 destinationDatasetId: dataset.datasetId,
15 scheduleOptions: { disableAutoScheduling: true },
16 params: {
17 query: "SELECT 1 AS n",
18 destination_table_name_template: "nightly",
19 write_disposition: "WRITE_TRUNCATE",
20 },
21 });
22});
23
24/**
25 * Effect-native Cloud Run service exercising every BigQuery Data Transfer
26 * binding as its own runtime service account. Deployed from
27 * {@link ../Bindings.test.ts}.
28 */
29export default class BigQueryDataTransferBindingsHost extends GCP.Function<BigQueryDataTransferBindingsHost>()(
30 "BigQueryDataTransferBindingsHost",
31 { main: import.meta.url, invokerIamDisabled: true },
32 Effect.gen(function* () {
33 const start = yield* GCP.BigQueryDataTransfer.StartManualRuns(Nightly);
34
35 return {
36 fetch: serveProbes({
37 startManualRuns: start({
38 body: { requestedRunTime: "2020-01-01T00:00:00Z" },
39 }),
40 }),
41 };
42 }).pipe(Effect.provide(GCP.BigQueryDataTransfer.StartManualRunsHttp)),
43) {}