How to compile and spawn/run the projects(http and worker) from a main application?

145 views Asked by At

I'm trying to learn D and hence setting upp a httpserver with a worker thread that can do stuff in its own loop ie. a main application that starts up by spawning http thread and the worker thread then also connect signal (SIGINT, &handler) to handle like Ctrl + C in main where handler function is in each spawned threads.

I'm using Vibe.d for the http server. The folder structure, where the root folder is the main application and with separate subfolders for http and worker project

Now my problem is the spawn part, how to get the worker going if that is its own project?

I've tried to import worker project but no luck I can't compile as I've learned the three .d files on a row

dub source/app.d aworker/source/app.d 

This gives me an error "The source file must start with a recipe comment"??? Answer to that you can see in dub commandline params

I've managed to spawn threads using dmd syntax but within same project in "call function in another file" question, now I want to separate projects as if a group of people are coding them separatly.

How do I compile and spawn/run several projects(http and worker) from a main application??

1

There are 1 answers

0
Anders S On

I have found the solution to my problem. spawnProcess Read more about it at dlang.org and spawnProcess

1) In my project group "spider", "server" and "worker", i have compiled all to individual applications using dub in resp. project folder.

2) From the "spider" application code, I thread out "server" and "worker" as subprocesses like this

import std.process;
auto workerId = spawnProcess(<path to worker as string>);
scope(exit)wait(workerId);
auto serverId = spawnProcess(<path to server as string>);
scope(exit)wait(serverId);

This leaves me with a single starting point and I run from a terminal, then it's the single terminal with all output like writeln a.s.o. from all processes. Still left to solve signal, but that looks like a minor problem ;)