Hello there, I''m still "new" to ruby on rails, i try to create a little browsergame. For that, I have to control the "resources" of a village. For example: The village got a wood rate of 200 per hour, so i want to call every hour a method/action (anything) that count the 200 to the rest wood. But of course, i need to do this with every village. Since yet I did some easy code with delayed job and it all worked fine, but now i think about how to create this big background job. One option to start it would be at the first creation of a village but how? But i thought about it, setting it up with delayed job and running an method that check hundreds of villages, it sounds a little nonproductive and a waste of time. Btw. that would mean, that one worker is all the time busy and can''t do anything else or not? I mean thats really annoying cause he is frozen for the most time - doing nothing. What of course mean i need a second worker and then heroku is not "for free" anymore? So what do you think is the best way(with or without delayed_job) to handle this job? Has anyone an example site which had the same problem? Ps: is there a way to start the code every full hour? I think using sleep could be a second problem with many villages. For that long running code it wouldn''t be anymore "every full hour" it would turn in every hour and a half, or not? Greetings Genji -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Genji wrote in post #1016820:> Hello there, > > I''m still "new" to ruby on rails, i try to create a little > browsergame. For that, I have to control the "resources" of a village. > For example: > The village got a wood rate of 200 per hour, so i want to call every > hour a method/action (anything) that count the 200 to the rest wood. > But of course, i need to do this with every village. > > Since yet I did some easy code with delayed job and it all worked > fine, but now i think about how to create this big background job. One > option to start it would be at the first creation of a village but > how? But i thought about it, setting it up with delayed job and > running an method that check hundreds of villages, it sounds a little > nonproductive and a waste of time. > Btw. that would mean, that one worker is all the time busy and can''t > do anything else or not? I mean thats really annoying cause he is > frozen for the most time - doing nothing. What of course mean i need a > second worker and then heroku is not "for free" anymore? > So what do you think is the best way(with or without delayed_job) to > handle this job? >It sounds like you could use a Queue with one worker. Of course with only one worker the tasks you add to the Q can only be executed one at a time> Has anyone an example site which had the same problem? > > Ps: is there a way to start the code every full hour?cron job. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Aug 16, 2011 at 7:09 AM, Genji <sushi.genji-PkbjNfxxIASELgA04lAiVw@public.gmane.org> wrote:> Hello there, > > I''m still "new" to ruby on rails, i try to create a little > browsergame. For that, I have to control the "resources" of a village. > For example: > The village got a wood rate of 200 per hour, so i want to call every > hour a method/action (anything) that count the 200 to the rest wood. > But of course, i need to do this with every village. > > Since yet I did some easy code with delayed job and it all worked > fine, but now i think about how to create this big background job. One > option to start it would be at the first creation of a village but > how? But i thought about it, setting it up with delayed job and > running an method that check hundreds of villages, it sounds a little > nonproductive and a waste of time. > Btw. that would mean, that one worker is all the time busy and can''t > do anything else or not? I mean thats really annoying cause he is > frozen for the most time - doing nothing. What of course mean i need a > second worker and then heroku is not "for free" anymore? > So what do you think is the best way(with or without delayed_job) to > handle this job? > > Has anyone an example site which had the same problem? > > Ps: is there a way to start the code every full hour? I think using > sleep could be a second problem with many villages. For that long > running code it wouldn''t be anymore "every full hour" it would turn in > every hour and a half, or not? > >Everytime the page loads, compute the total resources of the user based on the last time you updated the resources of that user. Then add a js that would send an ajax request that would update the resources. No background job needed. So for example, a user last logged out at 7:00 PM. The next day, that same user logged in at 7:30 AM. That would mean that that user''s resources should increase by 12 hours worth of resources and your js should fire after 30 mins.> Greetings > Genji > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jim ruther Nill wrote in post #1016826:> Everytime the page loadsThe user could have the page open for two hours. What then? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jim Ruther Nill
2011-Aug-16 06:12 UTC
Re: Re: Best way to create an endless Background job?
On Tue, Aug 16, 2011 at 9:42 AM, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Jim ruther Nill wrote in post #1016826: > > Everytime the page loads > > The user could have the page open for two hours. What then? > >After the js fires, set that same script to run after 1 hour.> -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
<html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#FFFFFF" text="#000000"> Hi,<br> <br> I think the best will be to set the os scheduler to launch a ruby script every hour to execute the task. I try to use delayed_jobs only when a user launches / start a process that is too big / too long and will affect the user experience.<br> <br> Good luck!<br> <br> El 16/08/2011 8:12, Jim Ruther Nill escribió: <blockquote cite="mid:CAJ8y7Vf5OSxob3fSX7xvZUyZwpaGRXxYZVQkVORL0b0HdLJRJw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org" type="cite"><br> <br> <div class="gmail_quote">On Tue, Aug 16, 2011 at 9:42 AM, 7stud -- <span dir="ltr"><<a moz-do-not-send="true" href="mailto:lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org">lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org</a>></span> wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> Jim ruther Nill wrote in post #1016826:<br> > Everytime the page loads<br> <br> The user could have the page open for two hours. What then?<br> <div class="im"><br> </div> </blockquote> <div><br> </div> <div>After the js fires, set that same script to run after 1 hour.</div> <div> </div> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> <div class="im"> --<br> Posted via <a moz-do-not-send="true" href="http://www.ruby-forum.com/" target="_blank">http://www.ruby-forum.com/</a>.<br> <br> --<br> </div> <div> <div class="h5">You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.<br> To post to this group, send email to <a moz-do-not-send="true" href="mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org">rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org</a>.<br> To unsubscribe from this group, send email to <a moz-do-not-send="true" href="mailto:rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org">rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org</a>.<br> For more options, visit this group at <a moz-do-not-send="true" href="http://groups.google.com/group/rubyonrails-talk?hl=en" target="_blank">http://groups.google.com/group/rubyonrails-talk?hl=en</a>.<br> <br> </div> </div> </blockquote> </div> <br> <br clear="all"> <div><br> </div> -- <br> -------------------------------------------------------------<br> visit my blog at <a moz-do-not-send="true" href="http://jimlabs.heroku.com">http://jimlabs.heroku.com</a><br> -- <br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.<br> To post to this group, send email to <a class="moz-txt-link-abbreviated" href="mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org">rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org</a>.<br> To unsubscribe from this group, send email to <a class="moz-txt-link-abbreviated" href="mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org">rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org</a>.<br> For more options, visit this group at <a class="moz-txt-link-freetext" href="http://groups.google.com/group/rubyonrails-talk?hl=en">http://groups.google.com/group/rubyonrails-talk?hl=en</a>.<br> </blockquote> <br> </body> </html> <p></p> -- <br /> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.<br /> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org<br /> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org<br /> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.<br />
Create an endpoint and call it using external cron service. http://www.setcronjob.com/ -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
+1 for Jim Ruther Hills recommendation. On Aug 15, 7:09 pm, Genji <sushi.ge...-PkbjNfxxIASELgA04lAiVw@public.gmane.org> wrote:> Hello there, > > I''m still "new" to ruby on rails, i try to create a little > browsergame. For that, I have to control the "resources" of a village. > For example: > The village got a wood rate of 200 per hour, so i want to call every > hour a method/action (anything) that count the 200 to the rest wood. > But of course, i need to do this with every village. > > Since yet I did some easy code with delayed job and it all worked > fine, but now i think about how to create this big background job. One > option to start it would be at the first creation of a village but > how? But i thought about it, setting it up with delayed job and > running an method that check hundreds of villages, it sounds a little > nonproductive and a waste of time. > Btw. that would mean, that one worker is all the time busy and can''t > do anything else or not? I mean thats really annoying cause he is > frozen for the most time - doing nothing. What of course mean i need a > second worker and then heroku is not "for free" anymore? > So what do you think is the best way(with or without delayed_job) to > handle this job? > > Has anyone an example site which had the same problem? > > Ps: is there a way to start the code every full hour? I think using > sleep could be a second problem with many villages. For that long > running code it wouldn''t be anymore "every full hour" it would turn in > every hour and a half, or not? > > Greetings > Genji-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you for the answers. Using a scheduler or a external cron service still means to use a worker, right? But would the "js - way" need a worker for that task? (js means java script or not?) The problem is just that i never did something with javascript... So maybe i could set it up like Jim said and using the rufus-scheduler in place of js (https://github.com/jmettraux/rufus-scheduler )? But there is one question left. Would this be more productive? I still have to check every user to know who is logged in and who is not. Would java script change this? Right now it would be: one process for all users -- long running would java script change it to : one process for one user without a background worker? btw: Cronjob sounds great for checking the points of the players... On 16 Aug., 11:37, Jigar Patel <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Create an endpoint and call it using external cron service. > > http://www.setcronjob.com/ > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jim Ruther Nill
2011-Aug-16 15:00 UTC
Re: Re: Best way to create an endless Background job?
On Tue, Aug 16, 2011 at 9:04 PM, Genji <sushi.genji-PkbjNfxxIASELgA04lAiVw@public.gmane.org> wrote:> Thank you for the answers. > > Using a scheduler or a external cron service still means to use a > worker, right? > But would the "js - way" need a worker for that task? (js means java > script or not?) > The problem is just that i never did something with javascript... > So maybe i could set it up like Jim said and using the rufus-scheduler > in place of js (https://github.com/jmettraux/rufus-scheduler )? > But there is one question left. > Would this be more productive? I still have to check every user to > know who is logged in and who is not. Would java script change this? > Right now it would be: > one process for all users -- long running > would java script change it to : > one process for one user without a background worker? > > btw: Cronjob sounds great for checking the points of the players... > >The main reason I suggested using js is so that the user''s view will always be updated and/or correct. Having a background job do the updates will only update the database. The user still has to refresh the page to get the current amount of resources. Or you''d still have to update the page via ajax so that the values are updated. To answer your question, a js will at most send 1 request to your server every hour, which is much more acceptable than sending a request to the server every minute just so that the server can update the resources'' values via ajax.> On 16 Aug., 11:37, Jigar Patel <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > Create an endpoint and call it using external cron service. > > > > http://www.setcronjob.com/ > > > > -- > > Posted viahttp://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Richard Holmes
2011-Aug-17 17:03 UTC
Re: Re: Best way to create an endless Background job?
On Aug 16, 2011, at 10:00 AM, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Tue, Aug 16, 2011 at 9:04 PM, Genji <sushi.genji-PkbjNfxxIASELgA04lAiVw@public.gmane.org> wrote: > Thank you for the answers. > > Using a scheduler or a external cron service still means to use a > worker, right? > But would the "js - way" need a worker for that task? (js means java > script or not?) > The problem is just that i never did something with javascript... > So maybe i could set it up like Jim said and using the rufus-scheduler > in place of js (https://github.com/jmettraux/rufus-scheduler )? > But there is one question left. > Would this be more productive? I still have to check every user to > know who is logged in and who is not. Would java script change this? > Right now it would be: > one process for all users -- long running > would java script change it to : > one process for one user without a background worker? > > btw: Cronjob sounds great for checking the points of the players... > > > The main reason I suggested using js is so that the user''s view will > always be updated and/or correct. Having a background job do the > updates will only update the database. The user still has to refresh > the page to get the current amount of resources. Or you''d still have > to update the page via ajax so that the values are updated. > > To answer your question, a js will at most send 1 request to your server > every hour, which is much more acceptable than sending a request to > the server every minute just so that the server can update the resources'' > values via ajax.One thing to keep in mind with the JavaScript method is that if a person wants to cheat they may be able to fake extra js requests. For multiplayer this may be a problem. Easily handled with a little extra checking on the server when the requests come in, though. -r> On 16 Aug., 11:37, Jigar Patel <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > Create an endpoint and call it using external cron service. > > > > http://www.setcronjob.com/ > > > > -- > > Posted viahttp://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > ------------------------------------------------------------- > visit my blog at http://jimlabs.heroku.com > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.