Skip to content

Instantly share code, notes, and snippets.

@jesspanni
Created April 24, 2019 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesspanni/d61370a54fb007581020aaa5d21b790f to your computer and use it in GitHub Desktop.
Save jesspanni/d61370a54fb007581020aaa5d21b790f to your computer and use it in GitHub Desktop.
SnowflakeLoadAzureFunction
[FunctionName("Load")]
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "v1/load")]
HttpRequestMessage req,
ILogger logger,
ExecutionContext context)
{
ServiceProvider serviceProvider = Initializer.Initialize(context);
string body = await req.Content.ReadAsStringAsync().ConfigureAwait(false);
LoadCommand command = JsonConvert.DeserializeObject<LoadCommand>(body);
if (!command.Validate(out string message))
{
return req.CreateResponse(HttpStatusCode.BadRequest, message);
}
IConfiguration config = serviceProvider.GetService<IConfiguration>();
var client = new SnowflakeClient(config["ConnectionString"]);
try
{
client.Load(command.Stage, command.TargetTable, command.Files, command.Warehouse, command.Database, command.Schema, command.Force);
}
catch (Exception e)
{
logger.LogError(e, "Error processing request");
return req.CreateResponse(HttpStatusCode.InternalServerError, e.Message);
}
return req.CreateResponse(HttpStatusCode.OK);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment