RoR Threads dissapear after sleep?










0















I have an issue with Threads in rails 4.
I want to open method in new Thread, that doesn't use ActiveRecord.
Method just sleeps for few minutes and then it just triggers post request.



Everything works fine, but sometimes some of those Threads newer trigger after sleep. Its mostly when spam like 20 of them, but sometimes its when there is just few. And in 3rd case even when I spam them, everything is OK. I tried with outputs in Threads before sleep and after, and before sleep message always outputs, meaning Thread is there, but after sleep one doesn't in occasions when it fails to send POST request.



sth = "array of ActiveRecord objects, like 10 max"

sth.each do |s|
..some active record create new object..unrelated..

Thread.new custom_method(s.id)
end

def custom_method(id)
Rails.logger.info "BEFORE SLEEP FOR #id"
sleep(180)
Thread.current.run # this is something that I just tried if it will help

..call post method to send "id" to some route, nothing special...

Thread.current.exit # also added to see if it will help
end


So basically, every time before sleep log message is seen, but the after one is not, and that POST request doesn't trigger in those cases. Any ideas why is this happening so randomly?



Thanks










share|improve this question


























    0















    I have an issue with Threads in rails 4.
    I want to open method in new Thread, that doesn't use ActiveRecord.
    Method just sleeps for few minutes and then it just triggers post request.



    Everything works fine, but sometimes some of those Threads newer trigger after sleep. Its mostly when spam like 20 of them, but sometimes its when there is just few. And in 3rd case even when I spam them, everything is OK. I tried with outputs in Threads before sleep and after, and before sleep message always outputs, meaning Thread is there, but after sleep one doesn't in occasions when it fails to send POST request.



    sth = "array of ActiveRecord objects, like 10 max"

    sth.each do |s|
    ..some active record create new object..unrelated..

    Thread.new custom_method(s.id)
    end

    def custom_method(id)
    Rails.logger.info "BEFORE SLEEP FOR #id"
    sleep(180)
    Thread.current.run # this is something that I just tried if it will help

    ..call post method to send "id" to some route, nothing special...

    Thread.current.exit # also added to see if it will help
    end


    So basically, every time before sleep log message is seen, but the after one is not, and that POST request doesn't trigger in those cases. Any ideas why is this happening so randomly?



    Thanks










    share|improve this question
























      0












      0








      0








      I have an issue with Threads in rails 4.
      I want to open method in new Thread, that doesn't use ActiveRecord.
      Method just sleeps for few minutes and then it just triggers post request.



      Everything works fine, but sometimes some of those Threads newer trigger after sleep. Its mostly when spam like 20 of them, but sometimes its when there is just few. And in 3rd case even when I spam them, everything is OK. I tried with outputs in Threads before sleep and after, and before sleep message always outputs, meaning Thread is there, but after sleep one doesn't in occasions when it fails to send POST request.



      sth = "array of ActiveRecord objects, like 10 max"

      sth.each do |s|
      ..some active record create new object..unrelated..

      Thread.new custom_method(s.id)
      end

      def custom_method(id)
      Rails.logger.info "BEFORE SLEEP FOR #id"
      sleep(180)
      Thread.current.run # this is something that I just tried if it will help

      ..call post method to send "id" to some route, nothing special...

      Thread.current.exit # also added to see if it will help
      end


      So basically, every time before sleep log message is seen, but the after one is not, and that POST request doesn't trigger in those cases. Any ideas why is this happening so randomly?



      Thanks










      share|improve this question














      I have an issue with Threads in rails 4.
      I want to open method in new Thread, that doesn't use ActiveRecord.
      Method just sleeps for few minutes and then it just triggers post request.



      Everything works fine, but sometimes some of those Threads newer trigger after sleep. Its mostly when spam like 20 of them, but sometimes its when there is just few. And in 3rd case even when I spam them, everything is OK. I tried with outputs in Threads before sleep and after, and before sleep message always outputs, meaning Thread is there, but after sleep one doesn't in occasions when it fails to send POST request.



      sth = "array of ActiveRecord objects, like 10 max"

      sth.each do |s|
      ..some active record create new object..unrelated..

      Thread.new custom_method(s.id)
      end

      def custom_method(id)
      Rails.logger.info "BEFORE SLEEP FOR #id"
      sleep(180)
      Thread.current.run # this is something that I just tried if it will help

      ..call post method to send "id" to some route, nothing special...

      Thread.current.exit # also added to see if it will help
      end


      So basically, every time before sleep log message is seen, but the after one is not, and that POST request doesn't trigger in those cases. Any ideas why is this happening so randomly?



      Thanks







      ruby-on-rails-4






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 6:06









      DevDev

      31210




      31210






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313387%2fror-threads-dissapear-after-sleep%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313387%2fror-threads-dissapear-after-sleep%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          Evgeni Malkin