0

I have some code which takes some incoming JSON, deserializes it and then simple stores it in a database

+----+---------------+
| Id | Json          |
+----+---------------+
| 1  | { json here } |
+----+---------------+
| 2  | {more json }  |
+----+---------------+


    [FunctionName("PostJson")]
    public async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
        HttpRequest req,
        ILogger log)
    {
        var content = await new StreamReader(req.Body).ReadToEndAsync();

        try { //deserialize and save to DB }

        catch (Exception e){ //log errors }

        return new OkObjectResult("Ok");
    }

Once this has returned.. How can I say "Ok this function has saved to DB, now take this content row that was just imported and call my "ProcessJson" function

i.e. I understand it would be another HTTP request? But at what point do i call the "Process Json" function and parse through that same content that was saved to the DB. The reason I want two processes is because the initial call to "PostJson" will then be faster for the "front end" side of things and then the large processing of data will all be server sided and wont intrude.

ScuffedCoder
  • 376
  • 1
  • 5
  • 21
  • What database are you using? – Chris Mar 04 '21 at 14:11
  • Using Microsoft SQL Server Management Studio. I think i'm just more curious on how can i call the next function knowing that initial incoming JSON is saved – ScuffedCoder Mar 04 '21 at 14:15
  • Couple of options from the top of my head - 1) Put a message on a queue when JSON has been successfully saved and have the next function trigger from the queue. 2) Use durable functions and call the next function once the JSON has been successfully saved. – Chris Mar 04 '21 at 14:18
  • Let's say I have a queue, i.e. my PostJson adds a queue message and stores in storage, and then i have a queue trigger which is for my process function. How would i access that original content that was posted in my "postJson" function in the "processJson" function? – ScuffedCoder Mar 04 '21 at 14:56
  • Can you read it from the database? Why do you need the original content? – Chris Mar 04 '21 at 15:33
  • That's true I could..but i ended up using the "myQueueItem" from `public async Task RunAsync([QueueTrigger("outqueue", Connection = "AzureWebJobsStorage")]string myQueueItem, ILogger log)` and i guess this worked too? – ScuffedCoder Mar 04 '21 at 16:05
  • So are you adding the content to the queue message? – Chris Mar 04 '21 at 16:17
  • I suppose so yes..in regards to efficiency i guess this wouldn't be ideal and should access direct from the DB then? I mean its not a large string so I wonder how much of a difference it would even make – ScuffedCoder Mar 04 '21 at 16:20

0 Answers0