Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the app with two apps and one database causes problems #7

Open
elie222 opened this issue Jul 28, 2015 · 16 comments
Open

Using the app with two apps and one database causes problems #7

elie222 opened this issue Jul 28, 2015 · 16 comments

Comments

@elie222
Copy link
Contributor

elie222 commented Jul 28, 2015

I've just deployed two apps that share a mongodb. When I uploaded the second app, all the users that were online in the first app were set to offline.
Not sure why that happened. Will have to dig into the code to understand, but it seems wrong if they're sharing the same database.

@rodrigok
Copy link
Contributor

I can't realize why.

Can you create an example? So I can debug and solve this problem.

@elie222
Copy link
Contributor Author

elie222 commented Jul 28, 2015

So I'm reading through the package code, and I've noticed that I'm not calling UserPresence.start() on the client. Only on the server. Is that wrong? Should it be called on both? Sort of confused how things have been working for me till now without calling UserPresence.start() client-side.

@rodrigok
Copy link
Contributor

Sorry about the documentation lack :(

Yes, you need to call the start on the client too to monitoring window focus, mouse event and key events to set user as away or online, monitoring the connection lost and reconnections too.

But, don't seems to be related with this issue.

@elie222
Copy link
Contributor Author

elie222 commented Jul 28, 2015

How has the package been working for me without doing that though?

@rodrigok
Copy link
Contributor

The server side set user as online and offline via connection of client with server. The client start is more important to monitor user and set as Away and Online based on user activity and window focus.

@elie222
Copy link
Contributor Author

elie222 commented Jul 28, 2015

Ah. Okay. Truth is I think I prefer it being based on the connection alone, so maybe I'll leave it as it is.

I'll get back to you with an example! 2 things I now need to get back to you about

@rodrigok
Copy link
Contributor

👍

@elie222
Copy link
Contributor Author

elie222 commented Jul 28, 2015

Just to add, I've stopped calling UserPresence.start() in my second app, and when redeploying, I didn't run into the problem I had the first time where no users were online.

@rodrigok
Copy link
Contributor

Are you using konecty:multiple-instances-status?

@elie222
Copy link
Contributor Author

elie222 commented Jul 28, 2015

yes

@rodrigok
Copy link
Contributor

In both apps?

@elie222
Copy link
Contributor Author

elie222 commented Jul 28, 2015

Yes. It's the same app. This is the code I was running server-side on startup in both instances:

  UserPresenceMonitor.start();
  UserPresence.start();

I'm now running the above code in only one instance, since users don't connect to the second instance anyway.

@elie222
Copy link
Contributor Author

elie222 commented Jul 28, 2015

I'm not running this code:

  // InstanceStatus.events.on('registerInstance', function(id, record) {
  //   console.log('registerInstance, pid:', record.pid);
  // });

  // InstanceStatus.registerInstance('Test');
  // InstanceStatus.activeLogs();

Should I be?

@rodrigok
Copy link
Contributor

I can't understand what you are trying to do hehe.

Can you explain your structure and where you are calling and what you are calling?

If you have only 1 project running in multiple instances you need to use the InstanceStatus and call the registerInstance to create 1 record in DB for each instance with a unique ID and the same name, so, when a instance starts, maybe after a die, the user status will remove all sessions that is linked to instance's ids that doesn't exists.

Start workflow

  1. 2 instances are started
  2. InstaceStatus register each instance
  3. UserStatus start in each instance and remove all sessions with instanceId not in the current registered instances to remove invalid status

Die workflow

  1. No instance restart, so DB remove the record of instance status because we don't have a heart beat in that instance, and the online instances removes all sessions linked to this instances that are been removed from the db
  2. A instance restart before the expiration time of DB, so this instance get all online instance's ids and remove all sessions that has diferente instance id.

If you don't use Instance Status when a new instance became active all sessions will be removed to prevent wrong statuses because I can't find witch session is related with witch instance.

@elie222
Copy link
Contributor Author

elie222 commented Jul 28, 2015

So running the following code server-side only should be fine?

Meteor.startup(function() {
    InstanceStatus.events.on('registerInstance', function(id, record) {
        console.log('registerInstance, pid:', record.pid);
    });

    InstanceStatus.registerInstance('Test');

    UserPresenceMonitor.start();

    UserPresence.start();
});

Could we give 'Test' a better name too? I removed it because I thought it wasn't important with the name 'Test'.

@rodrigok
Copy link
Contributor

Probably will be fine.

The name isn't importante, it's only if you need to see all applications that are online using the same DB, or packages. And if you want to use the InstanceStatus to do something like Arunoda does with microsevices discovering applications to call via registered names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants