How to wait for a specific Job to be processed inside a Controller #1108
-
I'm working on a Bid system (many items, and each one can have Bids offered for it). When a Bid is submitted, I'd like to process it inside a Job to guarantee that no two Bids are processed at the same time (so if two bidders offer the same price, the first bid is guaranteed to win). My questions is now around the need of the controller to wait for that Job, before returning the answer from the Controller. Maybe I could use Postgress Triggers, and watch for changes similar to how it's done on Runner.hs?- but I would also need to verify that the Job that triggered the change, is that Job the Controller inserted. So my Controller would maybe look something like this: action CreateBidAction = do
-- Create a "Mailbox", so once our Job is processed, we could return a response from the Controller.
mailbox <- newEmptyMVar
-- Create the Job
job <- newRecord @BidJob |> create
-- This non existing function, should wait for the trigger and compare it with
-- the created Job.
-- if Job is ours it will `putMvar` so Controller can proceed.
watchForJob job
-- Waiting for our Job..
receivedJob <- takeMvar mailbox So my question is how to approach the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You could try the following:
action CreateBidAction = do
job <- newRecord @BidJob |> create
redirectTo ShowBidJobAction { bidJobId = get #id bidJob }
action ShowBidJobAction { bidJobId } = autoRefresh do -- <---- we use auto refresh here
bidJob <- fetch bidJobId
bid <- fetch (get #bidId bidJob)
render ShowBidJobView { .. } with the view:
|
Beta Was this translation helpful? Give feedback.
-
Thanks @mpscholten! I guess with the new |
Beta Was this translation helpful? Give feedback.
You could try the following:
with the view: