bulk-importer worker so the link
worker stays focused on single links.
Add the worker
Scaffold the importer the same way you scaffoldedlink in Chapter 1:
Import a CSV over a channel
Thebulk-importer worker exposes one function that receives the read end of a channel, streams the
CSV in, and triggers link::create from the link worker for each row. Replace the generated
bulk-importer/src/index.ts:
bulk-importer/src/index.ts
See it work
With the engine running, let’s bulk-load some links.Unlike previous chapters this section and Chapter 7 require that you have node and npm
installed locally. This is because we’re now creating
client side code that runs outside of workers.
Upload a CSV
The uploader is a small standalone script that creates the channel, writes the CSV to the writer end, and hands the reader end tobulk-importer::import_csv. createChannel returns serializable
readerRef/writerRef handles you can pass through a normal trigger payload. It is not a worker,
so give it its own throwaway directory outside your project:
test-channels/import-links.js:
import-links.js
Conclusion
Linkly can now ingest a file’s worth of links in a single streamed upload through a dedicatedbulk-importer worker. Next, in Ch. 7: Bring in the browser, you turn
a browser tab into a worker that creates links and subscribes to the live click stream.