MCPcopy
hub / github.com/opentrace/opentrace / startImportFileJob

Method startImportFileJob

ui/src/job/browserJobService.ts:851–941  ·  view source on GitHub ↗
(
    file: File,
    name: string,
  )

Source from the content-addressed store, hash-verified

849 }
850
851 private async startImportFileJob(
852 file: File,
853 name: string,
854 ): Promise<JobStream> {
855 const channel = new EventChannel<JobEvent>();
856 let cancelled = false;
857
858 const run = async () => {
859 // 1. Read the binary database file
860 channel.push({
861 ...emptyEvent(),
862 kind: JobEventKind.JOB_EVENT_KIND_PROGRESS,
863 phase: JobPhase.JOB_PHASE_FETCHING,
864 message: `Reading ${name}`,
865 });
866
867 const buffer = await file.arrayBuffer();
868 const data = new Uint8Array(buffer);
869
870 channel.push({
871 ...emptyEvent(),
872 kind: JobEventKind.JOB_EVENT_KIND_STAGE_COMPLETE,
873 phase: JobPhase.JOB_PHASE_FETCHING,
874 message: `Read ${(data.byteLength / 1024 / 1024).toFixed(1)} MB`,
875 });
876
877 if (cancelled) return;
878
879 // 2. Import the database via the store's importDatabase method
880 if (!this.store.importDatabase) {
881 throw new Error('Store does not support database file import');
882 }
883
884 const result = await this.store.importDatabase(data, (msg) => {
885 channel.push({
886 ...emptyEvent(),
887 kind: JobEventKind.JOB_EVENT_KIND_PROGRESS,
888 phase: JobPhase.JOB_PHASE_SUBMITTING,
889 message: msg,
890 });
891 });
892
893 channel.push({
894 ...emptyEvent(),
895 kind: JobEventKind.JOB_EVENT_KIND_STAGE_COMPLETE,
896 phase: JobPhase.JOB_PHASE_SUBMITTING,
897 message: `Imported ${result.nodes_created} nodes, ${result.relationships_created} relationships`,
898 });
899
900 channel.push({
901 ...emptyEvent(),
902 kind: JobEventKind.JOB_EVENT_KIND_GRAPH_READY,
903 result: {
904 nodesCreated: result.nodes_created,
905 relationshipsCreated: result.relationships_created,
906 reposProcessed: 1,
907 },
908 });

Callers 1

startJobMethod · 0.95

Calls 4

pushMethod · 0.95
closeMethod · 0.95
emptyEventFunction · 0.85
runFunction · 0.50

Tested by

no test coverage detected