I’ve created something I don’t fully understand
My questions are essentially “what is and is-not reactive on the server?”.
I read the docs, but didn’t full grok them re: methods, timeouts, and collections.
I have two Meteor Micro-services. They are different meteor run
processes, and share the same MongoDB oplog.
The “add app” adds an item to a work queue collection. The “resolve app” let’s multiple people resolve them. The collection is published to both clients.
"add app" -[adds item]----> work queue collection
[oplog]
"resolve app" -[updates item]-> work queue collection
In “resolve app”, different users call a Meteor “resolve” method to respond yes/no/maybe to an item. The first “yes” get’s it. After a timeout, the first “maybe” get’s it.
The UI for this is working beautifully for one person on my laptop.
The 2 processes communicate using MongoDB oplog. The “resolve” method’s update checks the item’s status field so the updates don’t clobber:
var affected = queue.update(
{_id: item._id, status: item.status},
{status:newStatus}
);
if (!affected) throw new Meteor.Error('Someone else got there first. Try again later!');
If the update affects 0 rows, then throw an error and the client can try again after waiting for new data.
This also appears to be working well for one person on a laptop.
This approach doesn’t seem “reactive”, although it calls reactive things:
- The Meteor method
queue.findOne()
s the item. - The method sets a
Meteor.setTimeout()
to handle the maybes - The method/timeout
findOne()
andfind().count()
other collections.
My questions are this:
- In the method and timeout, am I leaking reactive calculations that I’m not aware of?
- This code is designed to run once for each method call. If the collection updates, before the method returns, will it run an extra time?
- Once the method and timeout return, is there anything leftover?
- If
affected
is 0, it’s a panic. Memory is out of sync with the db and I throw an Error. Is anything left over after that? - What is reactive on the server?
- How does this affect the “mergebox”?
- Is there an easier way?
- Am I shooting myself in the foot?
Sorry for the vague questions. I think it’s workable, but wanted to ask before having 1000 angry users.
Thanks!
Mike