You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've just discovered this project, and it looks fantastic. I decided to try it out on a little project, and am finding it challenging to get my bearings. Maybe someone can point me in the right direction. I'm trying to stick to the bog standard setup, using Doctrine ORM (which I'm very familiar with already).
My application is basically a job coordinator for a distributed-ish system. I've got a bunch of workers out in the world that do some long-running tasks. The coordination node is responsible for prioritizing tasks, and distributing to workers on request, and collecting results over time. So there's a basic model of a Task with composes the task parameters and results, and a model of a Reservation which is just "Task 123 is in-progress on worker123"/
Where I'm running into trouble is how to "reserve" a task. A Reservation is just a tuple of, like, (Task, worker_id). (worker_id is, for now, just a hostname). I've got a a nice entity that looks like:
finalclassReservation
{
privateTask$task;
privatestring$worker_id;
publicfunction__construct(Task$task, string$worker_id){
if ($task->getReservation()){ throw\Exception('Task is already reserved.');
$this->task = $task;
$this->worker_id = $worker_id;
}
}
I'd like my workers to reserve a job by doing something like POST /reservations with a request body like { "worker_id": "worker51" }, and get a serialized Reservation back.
I want my API logic to determine which of the pending tasks to give the worker. But api-platform doesn't seem like this so much, since it wants to create an Entity right away. It's not clear to me what I need to do in order to intercept the request and either provide the Task for the constructor argument, or new up the task myself, or what.
I looks like I could remove the $task argument from the constructor, introduce a setter, and use a Data Persister to add the Task that way. But I don't like the idea of allowing my entity to exist in an invalid state like that.
I'm fairly confident there's a good approach here, but I don't have my mind wrapped around all the moving pieces yet.
Can anyone point me in the right direction?
Edit: I think I want an Input DTO and DataTransformer as described here. Is that right?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I've just discovered this project, and it looks fantastic. I decided to try it out on a little project, and am finding it challenging to get my bearings. Maybe someone can point me in the right direction. I'm trying to stick to the bog standard setup, using Doctrine ORM (which I'm very familiar with already).
My application is basically a job coordinator for a distributed-ish system. I've got a bunch of workers out in the world that do some long-running tasks. The coordination node is responsible for prioritizing tasks, and distributing to workers on request, and collecting results over time. So there's a basic model of a
Task
with composes the task parameters and results, and a model of aReservation
which is just "Task 123 is in-progress on worker123"/Where I'm running into trouble is how to "reserve" a task. A Reservation is just a tuple of, like,
(Task, worker_id)
. (worker_id is, for now, just a hostname). I've got a a nice entity that looks like:I'd like my workers to reserve a job by doing something like
POST /reservations
with a request body like{ "worker_id": "worker51" }
, and get a serializedReservation
back.I want my API logic to determine which of the pending tasks to give the worker. But api-platform doesn't seem like this so much, since it wants to create an Entity right away. It's not clear to me what I need to do in order to intercept the request and either provide the Task for the constructor argument, or
new
up the task myself, or what.I looks like I could remove the
$task
argument from the constructor, introduce a setter, and use a Data Persister to add theTask
that way. But I don't like the idea of allowing my entity to exist in an invalid state like that.I'm fairly confident there's a good approach here, but I don't have my mind wrapped around all the moving pieces yet.
Can anyone point me in the right direction?
Edit: I think I want an Input DTO and DataTransformer as described here. Is that right?
Beta Was this translation helpful? Give feedback.
All reactions