{"action":"created","issue":{"url":"https://api.github.com/repos/lotus/lotus/issues/180","labels_url":"https://api.github.com/repos/lotus/lotus/issues/180/labels{/name}","comments_url":"https://api.github.com/repos/lotus/lotus/issues/180/comments","events_url":"https://api.github.com/repos/lotus/lotus/issues/180/events","html_url":"https://github.com/lotus/lotus/pull/180","id":60522600,"number":180,"title":"Preload application in config/environment file.","user":{"login":"smt116","id":619324,"avatar_url":"https://avatars.githubusercontent.com/u/619324?v=3","gravatar_id":"","url":"https://api.github.com/users/smt116","html_url":"https://github.com/smt116","followers_url":"https://api.github.com/users/smt116/followers","following_url":"https://api.github.com/users/smt116/following{/other_user}","gists_url":"https://api.github.com/users/smt116/gists{/gist_id}","starred_url":"https://api.github.com/users/smt116/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smt116/subscriptions","organizations_url":"https://api.github.com/users/smt116/orgs","repos_url":"https://api.github.com/users/smt116/repos","events_url":"https://api.github.com/users/smt116/events{/privacy}","received_events_url":"https://api.github.com/users/smt116/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"jodosha","id":5089,"avatar_url":"https://avatars.githubusercontent.com/u/5089?v=3","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"milestone":null,"comments":17,"created_at":"2015-03-10T15:57:26Z","updated_at":"2015-06-10T07:54:35Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/lotus/lotus/pulls/180","html_url":"https://github.com/lotus/lotus/pull/180","diff_url":"https://github.com/lotus/lotus/pull/180.diff","patch_url":"https://github.com/lotus/lotus/pull/180.patch"},"body":"Hi there,\r\n\r\nI had an issue with the `load_paths` and rake tasks / sidekiq workers.\r\n\r\n## Links\r\nThe background and problem is based on the following code: https://gist.github.com/smt116/db97a1929162f643e073\r\n\r\n## Background\r\nBasically I have `services` and `workers` directories in the `apps/streamer`:\r\n```\r\napps\r\n├── metrics\r\n[...]\r\n└── streamer\r\n    ├── application.rb\r\n    ├── services\r\n    │   └── foo.rb\r\n    ├── tasks\r\n    │   └── streamer.rake\r\n    └── workers\r\n        └── bar.rb\r\n```\r\nI have also `rake streamer:start` rake task which invokes `Streamer::Services::Foo.perform` action. This action streams messages from external, public API. After fetching each message, service passes it to the sidekiq worker which performs some actions on it and saves object into the database (slow `file_system` for test purposes). I have to use worker, because public API won't \"wait\" for my processing and it have to be as fast as it can.\r\n\r\n## Problem\r\nMy problem is that `rake streamer:start` **and** `bundle exec sidekiq -C config/sidekiq.yml -r./config/environment.rb` will result in `NameError: uninitialized constant Streamer::Services` exception. I can solve it by adding explicit requires to `config/environment.rb`:\r\n```\r\nrequire_relative '../apps/streamer/workers/bar'\r\nrequire_relative '../apps/streamer/services/foo'\r\n```\r\nbut the same should be done by `load_paths` from `apps/streamer/application.rb`. I don't want to specify the same thing in two different places each time ;)\r\n\r\n## Solution\r\nThe solution is to preload application in the `config/environment.rb` file so it will load proper files. I am playing with Lotus framework for 2 days now (and already love it :star2:) so not sure if it won't break something up.\r\n\r\nBtw. sidekiq works out-of-the-box:\r\n```\r\n# apps/streamer/workers/foo.rb\r\nrequire \"sidekiq\"\r\n\r\nmodule Streamer::Workers\r\n  class Foo\r\n    include Sidekiq::Worker\r\n\r\n    def perform(bar)\r\n      ...\r\n    end\r\n  end\r\nend\r\n\r\n# apps/streamer/application.rb\r\nmodule Streamer\r\n  class Application < Lotus::Application\r\n    configure do\r\n      root __dir__\r\n\r\n      load_paths << [\r\n        'workers',\r\n        'services'\r\n      ]\r\n\r\n      handle_exceptions false\r\n    end\r\n  end\r\nend\r\n\r\n# bundle exec sidekiq -C config/sidekiq.yml -r./config/environment.rb\r\n```"},"comment":{"url":"https://api.github.com/repos/lotus/lotus/issues/comments/110641690","html_url":"https://github.com/lotus/lotus/pull/180#issuecomment-110641690","issue_url":"https://api.github.com/repos/lotus/lotus/issues/180","id":110641690,"user":{"login":"AlfonsoUceda","id":925961,"avatar_url":"https://avatars.githubusercontent.com/u/925961?v=3","gravatar_id":"","url":"https://api.github.com/users/AlfonsoUceda","html_url":"https://github.com/AlfonsoUceda","followers_url":"https://api.github.com/users/AlfonsoUceda/followers","following_url":"https://api.github.com/users/AlfonsoUceda/following{/other_user}","gists_url":"https://api.github.com/users/AlfonsoUceda/gists{/gist_id}","starred_url":"https://api.github.com/users/AlfonsoUceda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlfonsoUceda/subscriptions","organizations_url":"https://api.github.com/users/AlfonsoUceda/orgs","repos_url":"https://api.github.com/users/AlfonsoUceda/repos","events_url":"https://api.github.com/users/AlfonsoUceda/events{/privacy}","received_events_url":"https://api.github.com/users/AlfonsoUceda/received_events","type":"User","site_admin":false},"created_at":"2015-06-10T07:54:35Z","updated_at":"2015-06-10T07:54:35Z","body":"@jodosha @smt116 any news about this?"}}