Added basic logging, just a facade for now

Added FissionContext class
Changed name on both class and function for input code to avoid namespace clashes when adding FissionContext
Updated README
Added section on how to develop/debug the code to README, might be obvious for some but not all
Changed code input from static function to method
This commit is contained in:
Klavs Madsen
2017-01-22 15:45:08 +01:00
parent f5270d97b1
commit 760e021141
8 changed files with 186 additions and 54 deletions
+22 -5
View File
@@ -1,4 +1,5 @@
using Fission.DotNetCore.Compiler;
using Fission.DotNetCore.Api;
using System.Collections.Generic;
using Nancy;
using System.IO;
@@ -8,9 +9,13 @@ namespace Fission.DotNetCore
{
public class ExecutorModule : NancyModule
{
#if DEBUG
private const string CODE_PATH = "/tmp/func.cs";
#else
private const string CODE_PATH = "/userfunc/user";
#endif
private static Function _userFunc;
private static Logger _logger = new Logger();
public ExecutorModule()
{
@@ -21,7 +26,6 @@ namespace Fission.DotNetCore
Head("/", _ => Run());
Options("/", _ => Run());
Delete("/", _ => Run());
}
private object Specialize()
@@ -34,7 +38,7 @@ namespace Fission.DotNetCore
if (_userFunc == null)
{
var errstr = string.Join(Environment.NewLine, errors);
Console.WriteLine(errstr);
_logger.WriteError(errstr);
var response = (Response)errstr;
response.StatusCode = HttpStatusCode.InternalServerError;
return response;
@@ -44,7 +48,9 @@ namespace Fission.DotNetCore
}
else
{
var response = (Response)"Unable to locate code";
var errstr = $"Unable to locate code at '{CODE_PATH}'";
_logger.WriteError(errstr);
var response = (Response)errstr;
response.StatusCode = HttpStatusCode.InternalServerError;
return response;
}
@@ -59,7 +65,18 @@ namespace Fission.DotNetCore
return response;
}
var args = ((DynamicDictionary)Request.Query).ToDictionary();
return _userFunc.Invoke(args);
try
{
return _userFunc.Invoke(new FissionContext(args, new Logger()));
}
catch (Exception e)
{
_logger.WriteError(e.ToString());
var response = (Response)e.Message;
response.StatusCode = HttpStatusCode.BadRequest;
return response;
}
}
}
}