Giter Club home page Giter Club logo

Comments (8)

dblock avatar dblock commented on August 11, 2024

In Rails you can start the server the same way in config.ru. If you look at the implementation of start_from_database!, it ends up calling start_async which doesn't block.

from slack-ruby-bot.

dblock avatar dblock commented on August 11, 2024

Share some more code if you can't get it to work! I'll close this for now.

from slack-ruby-bot.

torneco avatar torneco commented on August 11, 2024

Thanks for reply!
I could start slack-ruby-bot on Rails with config.ru!

If possible I want to manage separately Rails and slack-ruby-bot, but below codes didn't work. Do you have any idea?

Thanks

Gemfile

gem 'slack-ruby-bot', '~> 0.8.0'
gem 'celluloid-io', require: ['celluloid/current', 'celluloid/io']

Procfile

slack_server: bundle exec rails runner bin/slack_server
web: bundle exec rails server

bin/slack_server

SlackBotServer::App.instance.prepare!

Thread.abort_on_exception = true

Thread.new do
  SlacklBotServer::Service.start_from_database!
end

lib/slack-bot-server/app.rb

same as https://github.com/dblock/slack-bot-server/blob/master/slack-bot-server/app.rb

lib/slack-bot-server/service.rb

same as https://github.com/dblock/slack-bot-server/blob/master/slack-bot-server/service.rb

lib/slack-bot-server/server.rb

same as https://github.com/dblock/slack-bot-server/blob/master/slack-bot-server/server.rb

from slack-ruby-bot.

dblock avatar dblock commented on August 11, 2024

Define "doesn't work"?

Generally if you want your rails app to be also the registration for teams you're going to need a mechanism of telling the bot that a new team has been registered (they run in separate processes).

from slack-ruby-bot.

dblock avatar dblock commented on August 11, 2024

If the problem is bundle exec rails runner bin/slack_server, try bundle exec ruby bin/slack_server

from slack-ruby-bot.

torneco avatar torneco commented on August 11, 2024

Thanks again for your reply!

Define "doesn't work"?

Sorry for not explaining enough. I mean it doesn't start, throwing no error.

➜  testbot git:(master) ✗ bundle exec rails runner bin/slack_server.rb
I, [2016-05-25T11:10:28.532585 #10687]  INFO -- : Starting team #<Team:0x007feeaa789fb0>.
I, [2016-05-25T11:10:28.564831 #10687]  INFO -- : post https://slack.com/api/rtm.start
D, [2016-05-25T11:10:28.564899 #10687] DEBUG -- request: Accept: "application/json; charset=utf-8"
User-Agent: "Slack Ruby Client/0.7.3"
Content-Type: "application/x-www-form-urlencoded"
➜  testbot git:(master) ✗ 

So I tried to comment out Thread.new block and call bundle exec rails runner bin/slack_server.rb, got messages below;

# bin/slack_server.rb

SlackBotServer::App.instance.prepare!

# Thread.abort_on_exception = true

# Thread.new do
SlacklBotServer::Service.start_from_database!
# end
➜  testbot git:(master) ✗ bundle exec rails runner bin/slack_server.rb
I, [2016-05-25T10:43:02.193632 #9548]  INFO -- : Starting team #<Team:0x007f9aaaa0e230>.
I, [2016-05-25T10:43:02.235586 #9548]  INFO -- : post https://slack.com/api/rtm.start
D, [2016-05-25T10:43:02.235661 #9548] DEBUG -- request: Accept: "application/json; charset=utf-8"
User-Agent: "Slack Ruby Client/0.7.3"
Content-Type: "application/x-www-form-urlencoded"
I, [2016-05-25T10:43:03.218362 #9548]  INFO -- Status: 200
D, [2016-05-25T10:43:03.218459 #9548] DEBUG -- response: content-type: "application/json; charset=utf-8"
transfer-encoding: "chunked"
connection: "close"
access-control-allow-origin: "*"
cache-control: "private, no-cache, no-store, must-revalidate"
content-security-policy: "referrer no-referrer;"
date: "Wed, 25 May 2016 01:43:02 GMT"
expires: "Mon, 26 Jul 1997 05:00:00 GMT"
pragma: "no-cache"
server: "Apache"
strict-transport-security: "max-age=31536000; includeSubDomains; preload"
vary: "Accept-Encoding"
x-accepted-oauth-scopes: "rtm:stream,client"
x-content-type-options: "nosniff"
x-oauth-scopes: "identify,bot:basic"
x-xss-protection: "0"
x-cache: "Miss from cloudfront"
via: "1.1 f960dafcb3c8e2a2fc983a4e6653ee56.cloudfront.net (CloudFront)"
x-amz-cf-id: "8sf-oAkSs55E6a3ns878rZ1XeEFry3Fh_dLegM7TVhNtOCBkeaDCXg=="
D, [2016-05-25T10:43:03.233625 #9548] DEBUG -- Slack::RealTime::Concurrency::Celluloid::Socket#connect!: WebSocket::Driver::Client
➜  testbot git:(master) ✗ 

If the problem is bundle exec rails runner bin/slack_server, try bundle exec ruby bin/slack_server

It depends on ActiveRecord for this, I need to exec with rails runner...

Thank you

from slack-ruby-bot.

dblock avatar dblock commented on August 11, 2024

Your program just terminates, it doesn't block on anything and by its end a bunch of connections are being opened while it exits. All this starts asynchronously, something has to block forever. In a mixed example with Rails you have a web server waiting for connections, and in your you want this:

loop do
  Thread.pass
end

from slack-ruby-bot.

torneco avatar torneco commented on August 11, 2024

It works! ✨
Thank you for taking the time! 🙏

from slack-ruby-bot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.