2

My Meteor application, which up until recently was working fine, recently stopped working despite there having been no code changes to the application. I've confirmed the issue exists on three different machines with two different operating systems, so I don't think it's a hardware/software issue.

The primary issue (yes, there's more than one issue) is that my subscription isn't recognized as 'ready' even though the publish has been marked as ready and my records are available in the client.

Here's my code:

Publish:

Meteor.publish 'tickets', (selectedSquad) ->
  self = this
  unformattedTickets = [ array of objects coming from JIRA API ]
  _(unformattedTickets).forEach (issue) ->
    doc =
      normalizedColumn1: issue.fields.col
      ...
    self.added 'tickets', Random.id(), doc
  console.log 'publish ready'
  self.ready()

Subscribe:

Tracker.autorun ->
  @ticketSubscriptionHandle = Meteor.subscribe('tickets', Session.get('selectedSquad'))

Autorun for homepage:

Tracker.autorun ->
  if ticketSubscriptionHandle.ready()
    console.log 'ready'  
    doSomething()

I can see in my server 'publish ready', I can query Tickets.find() in my console, yet ticketSubscriptionHandle.ready() returns false, 'ready' isn't logged and doSomething() doesn't run.

As far as I can tell I'm using subscriptions/autorun exactly as specified in the docs. I also don't understand how this could have possibly stopped working without modifying the code or the version of meteor being used.

If you want to see the complete code base, it's available on GitHub at https://github.com/jprince/kanburn

Any help would be appreciated.

jprince
  • 181
  • 3
  • 11
  • Is the ticketSubscriptionHandle object available at all in your homepage autorun? You might have a scope issue with Coffeescript. – Sander van den Akker Feb 28 '15 at 08:41
  • Yes, it is available. – jprince Feb 28 '15 at 22:59
  • I think I've gotten to the bottom of this... my application uses a Bootstrap carousel to rotate through a series of D3 charts. Those charts are populated with data based on the `selectedSquad`. Upon completion of a cycle the `selectedSquad` toggles and data is requested for the next squad. It seems that my data, coming from the JIRA API, is being retrieved more slowly now, causing the carousel to cycle and toggle squads before the data ever renders, leaving me with a perpetual cycle of reactive reloads. That explains why this seeming broke with no change to the code. Thanks for help, guys. – jprince Mar 02 '15 at 04:08

1 Answers1

1

This is not an answer, but it may help you.

Note that the following code:

Tracker.autorun ->
  @ticketSubscriptionHandle = Meteor.subscribe('tickets', Session.get('selectedSquad'))

must be executed before the following code:

Tracker.autorun ->
  if ticketSubscriptionHandle.ready()
    console.log 'ready'  
    doSomething()

Is that the case? And even if it is, there's still a problem. When you execute Session.set('selectedSquad', "a-new-value"), the first autorun will re-run. You're expecting the other autorun to re-run as well, right? It won't, since ticketSubscriptionHandle isn't is a reactive variable.

Peppe L-G
  • 7,351
  • 2
  • 25
  • 50
  • I can confirm that the first autorun is executing before the one on the homepage. To your other point, ticketSubscriptionHandle itself isn't reactive, but the `.ready()` method is, as per https://www.discovermeteor.com/blog/reactivity-basics-meteors-magic-demystified/ – jprince Feb 28 '15 at 22:57
  • Regarding my other point: yes, the second autorun will correctly register a dependency in the subscriptionhandle's `ready` method, and when the first autorun is re-executed, `ticketSubscriptionHandle` will get a new value, but no dependency your second autorun depends on will have changed, so it won't get re-executed. – Peppe L-G Mar 01 '15 at 07:37