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

Error on publish "eventmachine not initialized" #5

Closed
HelloGrayson opened this issue Jul 9, 2013 · 19 comments
Closed

Error on publish "eventmachine not initialized" #5

HelloGrayson opened this issue Jul 9, 2013 · 19 comments

Comments

@HelloGrayson
Copy link

I get this error when calling the pubnub.publish method for reasons that are unclear:

Network Error: eventmachine not initialized: evma_connect_to_server

My code looks like such.

PUBNUB = new(
    :publish_key => CONFIG['pubnub']['publish_key'],
    :subscribe_key => CONFIG['pubnub']['subscribe_key'],
    :secret_key => CONFIG['pubnub']['secret_key'],
    :cipher => nil,
    :ssl => false
)

def callback(message)
    if message['occupancy'] <= 0
        return # no clients
    end
    publish_all()
end

def publish_all()
    PUBNUB.publish(
        :channel => 'stacks',
        :message => 'hi',
        :callback => lambda { |message|
            puts message
        }
    )
end

loop do

    # this works...
    #publish_all()
    #sleep 3

    # this doesnt work...
    PUBNUB.here_now(
        :channel => 'stacks',
        :callback => method(:callback)
    )
    sleep 3
end

I'm using ruby 2.0.0 with pubnub (3.3.0.7)

Any help would be swell.

@geremyCohen
Copy link
Contributor

hmm.. looks pretty boilerplate. how often do you get this, and how fast are you publishing ?

@HelloGrayson
Copy link
Author

@geremyCohen I've isolated the issue a bit more. Check out the updated code above.

@geremyCohen
Copy link
Contributor

Are you using any other EM-based code that may be stopping/restarting the reactor ? And please tell me how often it occurs, how fast you are publishing?

@geremyCohen
Copy link
Contributor

ok, thanks, I didnt get the page update until just now.

@geremyCohen
Copy link
Contributor

This is strange. Seems like some sort of scoping issue on the callback.

# This works

      @@pn.here_now(
          :channel => 'stacks',
          :callback => method(:puts)
      )

but

# This does not work

      @@pn.here_now(
          :channel => 'stacks',
          :callback => method(:callback)
      )

@geremyCohen
Copy link
Contributor

wait, thats not it. still researching...

@HelloGrayson
Copy link
Author

@geremyCohen thanks... I can't seem to figure it out. Do you have a hack that would work in the interim?

@geremyCohen
Copy link
Contributor

I see the issue, and I will see if I can find a workaround or fix for you...

@geremyCohen
Copy link
Contributor

Does your app require EM anywhere else?

@HelloGrayson
Copy link
Author

Not in any of my files. Here are my gem's

Gems included by the bundle:
  * activesupport (4.0.0)
  * addressable (2.3.5)
  * ansi (1.4.3)
  * atomic (1.1.10)
  * aws-sdk (1.11.3)
  * builder (3.2.2)
  * bundler (1.3.5)
  * commander (4.1.3)
  * cookiejar (0.3.0)
  * em-http-request (1.1.0)
  * em-socksify (0.3.0)
  * eventmachine (1.0.3)
  * factory_girl (4.2.0)
  * hashie (2.0.5)
  * highline (1.6.19)
  * hoe (3.6.3)
  * http_parser.rb (0.6.0.beta.2)
  * i18n (0.6.4)
  * json (1.8.0)
  * macaddr (1.6.1)
  * minitest (4.7.5)
  * minitest-reporters (0.14.20)
  * multi_json (1.7.7)
  * nokogiri (1.5.10)
  * powerbar (1.0.11)
  * promise (0.3.0)
  * pubnub (3.3.0.7)
  * rack (1.5.2)
  * rack-protection (1.5.0)
  * rack-test (0.6.2)
  * rake (10.1.0)
  * shotgun (0.9)
  * simple_mock (0.0.2)
  * sinatra (1.4.3)
  * systemu (2.5.2)
  * terminal-table (1.4.5)
  * test-unit (1.2.3)
  * thread_safe (0.1.0)
  * tilt (1.4.1)
  * tzinfo (0.3.37)
  * uuid (2.3.7)
  * uuidtools (2.1.4)
  * yajl-ruby (1.1.0)

@HelloGrayson
Copy link
Author

My Gemfile is probably more helpful:

source 'https://rubygems.org'

gem 'aws-sdk', '~> 1.0'
gem "pubnub", "~> 3.3.0.7"
gem 'sinatra'
gem 'shotgun'
gem 'commander'
gem 'terminal-table'
gem 'promise'

group :test do
    gem "test-unit", "1.2.3"
    gem "rack-test"
    gem "simple_mock", "~> 0.0.2"
    gem "factory_girl", "~> 4.0"
    gem "minitest-reporters"
end

@geremyCohen
Copy link
Contributor

The issue occurs because we are chaining calls. This is an issue with this version of the gem. Our new gem is in closed beta that lets you chain stuff... let me know if you'd be interested in checking it out.

In the meantime, the easiest workaround for you is to use our blocking publish for your publish: https://github.com/pubnub/ruby/blob/master/3.3/app/models/blocking_pub.rb

This way, there is no race condition between the two operations.

But real solution is in new version, let me know if you are interested in checking it out.

geremy

@HelloGrayson
Copy link
Author

@geremyCohen can I ask why callbacks are used at all? I don't really see the reason for non-blocking in the case of here_now or publish at least...

@geremyCohen
Copy link
Contributor

The new gem lets you choose whether or not to use callbacks or blocks, and whether to block or not in the response. :)

@geremyCohen
Copy link
Contributor

In general, if you are concerned about server response before continuing, you can block and wait for it and handle it as it happens. Otherwise, if you choose to be fully async and not block using callbacks, you can do that as well.

@HelloGrayson
Copy link
Author

@geremyCohen eta on the new gem?

@geremyCohen
Copy link
Contributor

I can send it to you... contact us at support @ pubnub and we'll set you up (its a closed beta)

@HelloGrayson
Copy link
Author

done.

@geremyCohen
Copy link
Contributor

cool. we also tested your code on it successfully. I'll followup shortly offline via email.

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