Queue has multiple actors in it, how does one process it? - message-queue

I apologise for the super basic question, I'm still trying to learn how to work with message queues.
The case:
Each user has a "worker" that can only process one task at a time for that user. If a queue looks like this:
[
{ taskForUser: 4, data { ...payload } },
{ taskForUser: 3, data { ...payload } },
{ taskForUser: 4, data { ...payload } },
{ taskForUser: 1, data { ...payload } },
{ taskForUser: 2, data { ...payload } },
{ taskForUser: 2, data { ...payload } },
{ taskForUser: 1, data { ...payload } },
{ taskForUser: 1, data { ...payload } }
]
I'd like to ensure that each user's worker is occupied with no one sitting idle, and as soon as a job for that user is completed, I'd like that user to take the next job for themselves.
Essentially, this feels like multiple queues - a queue for each user.
For simplicity, seems like dynamically creating a queue for each new user sign up seems like a decent solution. However that would have issues like polling SQS too much.
Perhaps I fundamentally misunderstand how SQS works, but how best do I solve this?

Related

JSON Database doesn't work correctly as per REST technique

I created a JSON server and this is the data that I'm using. However, when I'm trying to query the examlist and relate it to the students (i'd like to receive the students based on their ID (the picture below shows the REST query - I'm using ?_expand=student )) it won't display them. The code shows correct as per JSON validators, but my goal is to have them working.
The way my data is organized (the examlist table) won't display the students, because apparently, it cannot read their IDs. This database will be used for HTTP requests, hence I need it fully working.
I'll upload another image so that you can visualize my code.
Momentarily instead of my studentIDs, it's showing some random 0,1 numbers and the student IDs are being pushed down along the arbitrary tree.
(Just the examlist "table")
It's M:M relationship (relational database) and how I want it structured is:
Table "students" that contains information about the students;
I have "table" exams that contains information about the exams;
And then I have another "table" examlist which contains information about the EXAM (ExamID) and the students enrolled in it (basically relates the two abovementioned tables)
When I try querying the students through the "examlist" table, it won't work. However, the other "table" -- exam, does work.
My assumption is the way I have organized the students in the examlist "table" is not good, however, given my very little experience I cannot seem to see where the issue is.
I hope I cleared it out for the most of you! Sorry for any inconvenience caused.
{
"students": [
{
"id": 3021,
"nume": "Ionut",
"prenume": "Grigorescu",
"an": 3,
"departament": "IE"
},
{
"id": 3061,
"nume": "Nadina",
"prenume": "Pop",
"an":3,
"departament": "MG"
},
{
"id": 3051,
"nume": "Ionut",
"prenume": "Casca",
"an": 3,
"departament": "IE"
}
],
"exams": [
{
"id": 1,
"subiect": "Web Semantic",
"profesor": {
"Nume": "Robert Buchman"
}
},
{
"id": 2,
"subiect": "Programare Web",
"profesor": {
"Nume": "Mario Cretu"
}
},
{
"id": 3,
"subiect": "Medii de Programare",
"profesor": {
"Nume": "Valentin Stinga"
}
}
],
"listaexamene": [
{
"examId":1,
"Data Examen":"02/06/2022 12:00",
"studentId":
[
{
"id":3021
},
{
"id":3051
}
]
},
{
"examId":2,
"Data Examen":"27/05/2022 10:00",
"studentId":
[
{
"id":3021
},
{
"id":3051
}
]
},
{
"examId":1,
"Data Examen":"04/06/2022 10:00",
"studentId":
[
{
"id":3021
},
{
"id":3051
},
{
"id":3061
}
]
}
]
}
I had to repost with more information after my first one got closed down
I think I finally got the answer. The problem lays in the JSON server. Apparently, it cannot obtain information from further down the arbitrary tree, only the first layer.
Thank you all for your input on the previous post!

What result from REST endpoint is more common?

We are during design of our REST-API and we are wondering in what form REST endpoint should return data?
We have an endpoint that returns so-called "identity" objects that have different attributes.
Each 'identities' has unique string eg. UUID#cf684c35-200e-4936-8b63-e6e51b6e3569.
We are wondering which format the developers are more used to?
Like this below:
{
"UUID#cf684c35-200e-4936-8b63-e6e51b6e3569": {
"validity_date": 1608591121,
"visibility": "private"
},
"RFID#cf684c35-200e-4936-8b63-e6e51b6e3570": {
"validity_date": 1608591123,
"visibility": "public".
}
}
or
{
"results": [
{
"identity": "UUID#cf684c35-200e-4936-8b63-e6e51b6e3569",
"validity_date": 1608591121,
"visibility": "private"
},
{
"identity": "RFID#cf684c35-200e-4936-8b63-e6e51b6e3570",
"validity_date": 0,
"visibility": "1608591123"
},
]
}
What is your opinion?
TL;DR I recommend to use a list of objects (your second approach).
Let's take your objects to a more obvious example of users with an id and a name:
{
1: {
"name": "Michal"
},
2: {
"name": "Thomas"
}
}
[
{
"id": 1,
"name": "Michal"
},
{
"id": 2,
"name": "Thomas"
}
]
Both approaches can be used, I don't see any difference from the API-level itself.
But let's consider how an application might provide or consume such data:
fetching a database table of users (e.g. whose birthday is next week)
showing a table of users (e.g. user name and birthday)
processing the monthly salary to employees
All three examples use a list of users, which is the second approach. Since many applications operate on a list of entities, that's a common sense for APIs.
I think that it [] is better than it { "results": [] }.
Said it, on my opinion the 2nd is better because of [on some languages] is easier to map it than to map the 1st.

How to query data inside subobjects in MongoDB?

I need to query data in MongoBD and my JSON files look like the below.
The problem is that the time/date stamp changes for every five minutes so MongoDB understands the files as having different keys, for example "2018-01-02T00:00:00+09:00" and "2018-01-02T00:05:00+09:00" are different keys.
Finally, how would I query for when T1 is below 280?
I have taken a look at elemMatch but it is for arrays and not subobjects.
I am starting in MongoDB world so I am sorry if this is a silly question but I could not find the answer for it anywhere.
File 1
{
"2018-01-02T00:00:00+09:00": {
"141474": {
"T1": 276.5029,
"T2": 279.3629
},
"141475": {
"T1": 280.1534,
"T2": 279.7219
},
}
}
File 2
{
"2018-01-02T12:00:00+09:00": {
"141474": {
"T1": 275.1324,
"T2": 276.9986
},
"141475": {
"T1": 267.3324,
"T2": 250.6574
},
}
}

Organize data on hybrid-mobile-app

I am developing an Ionic app that must be able to operate offline. Being so I receive from the backend a JSON object called data that contains all the info I need and this object get updated at times using a diff algorithm.
The data comes like that:
{
"foos": [
{"id": 1, "name": "foo1"},
{"id": 2, "name": "foo2"}
],
"bars": [
{"id": 1, "name": "bar1", "fooId": 1},
{"id": 2, "name": "bar2", "fooId": 2}
]
}
I would like to have a specialized layer from where I can call for example findFooById(bars[i].fooId)
I am wondering what is the best way to achieve that and if there is something out of the box.
I think your best solution is to revisit your data structure in general as it looks overly complicated and I can't see a benefit to it.
But, general algorithm would be easy:
function findFooById(fooId) {
for (var x = 0; x < foos.length; x++){
if (foos[x].id == fooId) { return foos[x]; }
}
return false;
}

Parse Push Notifications to multiple users through REST API

I'm sending push notifications from a rails app through the parse.com REST API.
Targeting a single user works great but targeting more users with $in doesn't seem to work in my scenario.
Here's my JSON Code:
{
"where":
{
"user":
{
"__type":"Pointer",
"className":"_User",
"objectId":
{
"$in":["AAA","BBB","CCC"]
}
}
},
"data":
{ ...
Isn't it possible to use $in when targeting multiple users? I noticed that I'm also not able to to so in the parse.com push backend.
The response is:
{
"code": 106,
"error": "key objectId should be a string"
}
Anyone got an idea? I don't want to make an separate REST Call for every notification.
Okay, sorry I found the answer here: REST in Parse $in to ObjectID of Pointer Error Code 106
Or in short, this code works:
{
"where":
{
"user":
{
"$inQuery":
{
"where": {
"objectId":
{
"$in":["AAA","BBB","CCC"]
}
},
"className":"_User"
}
}
},
"data":