diff --git a/README.md b/README.md index dd763c2..326c176 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # create-schematic-gen-site + Simple HTTP server for generating schematics, used with my Materials-Extractor program. diff --git a/build-and-deploy-ldc2.sh b/build-and-deploy-ldc2.sh new file mode 100755 index 0000000..bf6fcd5 --- /dev/null +++ b/build-and-deploy-ldc2.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +dub clean +rm -f create-schematic-gen-site +dub build --compiler=/opt/ldc2/ldc2-1.33.0-linux-x86_64/bin/ldc2 --build=release --force +echo "Stopping CSGS service." +ssh -f root@andrewlalis.com 'systemctl stop csgs' +echo "Uploading new binary." +scp create-schematic-gen-site root@andrewlalis.com:/opt/create-schematic-gen-site/ +echo "Starting CSGS service." +ssh -f root@andrewlalis.com 'systemctl start csgs' diff --git a/dub.json b/dub.json index f8b4ca7..7bc2b0c 100644 --- a/dub.json +++ b/dub.json @@ -4,7 +4,7 @@ ], "copyright": "Copyright © 2023, Andrew Lalis", "dependencies": { - "handy-httpd": "~>7.6.4", + "handy-httpd": "~>7.7.0", "requests": "~>2.1.1", "scheduled": "~>1.2.0", "slf4d": "~>2.4.2" diff --git a/dub.selections.json b/dub.selections.json index b3b5e0c..0070ff0 100644 --- a/dub.selections.json +++ b/dub.selections.json @@ -4,10 +4,10 @@ "automem": "0.6.9", "cachetools": "0.4.1", "cronexp": "0.1.0-beta3", - "handy-httpd": "7.6.4", + "handy-httpd": "7.7.0", "httparsed": "1.2.1", "requests": "2.1.1", - "scheduled": "1.1.0", + "scheduled": "1.2.0", "slf4d": "2.4.2", "streams": "3.5.0", "test_allocator": "0.3.4", diff --git a/source/csgs/http.d b/source/csgs/http.d index 3d9c312..be070b2 100644 --- a/source/csgs/http.d +++ b/source/csgs/http.d @@ -15,10 +15,11 @@ void startServer() { config.port = 8100; PathDelegatingHandler handler = new PathDelegatingHandler(); - handler.addMapping("POST", "/extracts", &handleExtract); - handler.addMapping("GET", "/extracts/{extractId}", &getExtract); - handler.addMapping("POST", "/item-reports", &handleItemReport); - handler.addMapping("GET", "/status", (ref HttpRequestContext ctx) { + handler.addMapping(Method.GET, "/extracts", &handleExtract); + handler.addMapping(Method.GET, "/extracts/{extractId}", &getExtract); + handler.addMapping(Method.POST, "/item-reports", &handleItemReport); + handler.addMapping(Method.GET, "/item-reports", &getItemReports); + handler.addMapping(Method.GET, "/status", (ref HttpRequestContext ctx) { ctx.response.setStatus(HttpStatus.OK); ctx.response.writeBodyString("online"); }); @@ -34,7 +35,7 @@ private void handleExtract(ref HttpRequestContext ctx) { MultipartFormData data = ctx.request.readBodyAsMultipartFormData(); if (!validateExtractRequest(data, ctx.response)) return; string extractId = doExtract(data); - JSONValue result = JSONValue.emptyObject; + JSONValue result = JSONValue(string[string].init); result.object["extractId"] = JSONValue(extractId); ctx.response.writeBodyString(result.toJSON(), "application/json"); } @@ -54,3 +55,8 @@ private void handleItemReport(ref HttpRequestContext ctx) { f.writeln(itemName); f.close(); } + +private void getItemReports(ref HttpRequestContext ctx) { + import handy_httpd.components.responses : fileResponse; + fileResponse(ctx.response, "item-reports.txt", "text/plain"); +} diff --git a/source/csgs/task.d b/source/csgs/task.d index 06902c1..042d32d 100644 --- a/source/csgs/task.d +++ b/source/csgs/task.d @@ -2,6 +2,7 @@ module csgs.task; import slf4d; import scheduled; +import scheduled.taskpool_scheduler; import std.datetime; import std.typecons; @@ -13,11 +14,14 @@ import std.stdio; import csgs.extract; void startScheduledTasks() { - JobScheduler scheduler = new ThreadedJobScheduler(); + JobScheduler scheduler = new TaskPoolScheduler(); + Job cleanJob = new FunctionJob(&cleanOldExtracts); scheduler.addJob(cleanJob, new FixedIntervalSchedule(days(1))); + Job updateCheckJob = new FunctionJob(&checkForExtractorUpdate); scheduler.addJob(updateCheckJob, new FixedIntervalSchedule(hours(1))); + scheduler.start(); }