Well, lo and behold, its working -- on the Aspen stack, no less!  The
trick was to keep the code block in the controller or model the action
was being called from.

The only thing not working at this point is adding a worker when one
is already running.

heroku.set_workers(ENV['HEROKU_APP'], +1) sets workers to 1, rather
than adding 1 to the total.

heroku.set_workers(ENV['HEROKU_APP'], -1) definitely subtracts a
worker, though.

So I guess I'll try assigning the current number of workers to a
variable, add one to that variable, and place it where the quantity
goes in the set_workers command.

Problem solved!

Thanks again for the help, folks.


On Jan 25, 8:09 am, rubynoob <[email protected]> wrote:
> Dammit!  I pressed the space bar and inadvertently posted before I was
> done typing the message!  :/
>
> That code block obviously should have and 'end,' so here it is:
>
> end
>
> There, I feel better now.
>
> On Jan 25, 8:06 am, rubynoob <[email protected]> wrote:
>
> > I've been told by Heroku Support that we need to migrate to the Bamboo
> > stack, upgrade our heroku and rest-client gems to the latest, and this
> > should work.  Thanks to this community's help, I should be able to add
> > or subtract workers with just a few lines of code!
>
> > add_heroku_worker
> > heroku = Heroku::Client.new(ENV['HEROKU_USERNAME'],
> > ENV['HEROKU_PASSWORD'])
> > heroku.set_workers(ENV['HEROKU_APP'], +1)
>
> > Thanks, everyone!
> > Jim
>
> > On Jan 21, 10:07 am, rubynoob <[email protected]> wrote:
>
> > > @Pedro:
>
> > > Here's a link to the stack 
> > > trace:https://docs.google.com/document/d/1ntWg7PKgyOnSmAVkURW00O5i_LEDFdRsc...
>
> > > We're using RestClient gem version 1.4.2 with the Heroku gem version
> > > 1.17.8, FWIW.
>
> > > @Chris:  That is good to know.  So it sounds like I don't need to
> > > introduce a lag as Keenan suggests.
>
> > > Thanks,
> > > Jim
>
> > > On Jan 21, 9:01 am, Chris Hanks <[email protected]> wrote:
>
> > > > You can start up as many workers (or dynos, for that matter) as you
> > > > want through the command line. 24 is just how high the slider goes on
> > > > the pricing page.
>
> > > > On Jan 21, 7:52 am, rubynoob <[email protected]> wrote:
>
> > > > > I may misunderstand how workers get charged on heroku, but from what
> > > > > I've seen 
> > > > > athttp://docs.heroku.com/background-jobsandhttp://docs.heroku.com/delay...,
> > > > >  workers get charged $0.05/hr each
> > > > > no matter how many are running, pro-rated to the second.  The maximum
> > > > > workers per account seems to be 24 (that's where the slider stops on
> > > > > their Resources page).
>
> > > > > The jobs being delayed won't be created faster than one every 30
> > > > > seconds, so I assumed the first worker would spin up and grab the
> > > > > first job, then when the second job gets queued, a second worker would
> > > > > start, grabbing the second job, and so on.  Each job would process in
> > > > > it's own worker, which would then get shut down when the job
> > > > > completes.  One worker running three jobs that take a total of fifteen
> > > > > minutes to process should get charged the same as three workers
> > > > > running one job each for five minutes.  If I'm mistaken, let me know.
>
> > > > > Thanks,
> > > > > Jim
>
> > > > > On Jan 20, 4:57 pm, Keenan Brock <[email protected]> wrote:
>
> > > > > > Also a thought.
>
> > > > > > You will need to introduce a lag when you are determining if you 
> > > > > > need more or less delayed job workers.
>
> > > > > > Otherwise you will spin up too many DJs too quickly. And add/remove 
> > > > > > them very often. Incurring extra charges.
>
> > > > > > Smugmug spoke about this when they were talking about their on 
> > > > > > demand photo processors a few years back.
>
> > > > > > --Keenan
>
> > > > > > On Jan 20, 2011, at 6:06 PM, Pedro Belo <[email protected]> wrote:> 
> > > > > > That was a good call, you definitely don't want to store variables 
> > > > > > in
> > > > > > > config vars. Save if for constants (passwords, urls, etc).
>
> > > > > > > It seems like you might be getting an error due to different 
> > > > > > > versions
> > > > > > > of RestClient, not sure though. What version are you using? 
> > > > > > > What's the
> > > > > > > stack trace for the exception?
>
> > > > > > > On a side note, if it helps you can call heroku workers passing
> > > > > > > relative values, like +3, -1, etc.
>
> > > > > > > On Thu, Jan 20, 2011 at 12:00 PM, rubynoob 
> > > > > > > <[email protected]> wrote:
> > > > > > >> Instead of storing the count of active workers as a heroku config
> > > > > > >> variable, I decided to create a table in our database to store 
> > > > > > >> the
> > > > > > >> value in.
> > > > > > >> So now I've got the problem narrowed down to the last line in the
> > > > > > >> method.  Here's the block of code I've now got:
>
> > > > > > >> add_heroku_worker
> > > > > > >>                heroku = 
> > > > > > >> Heroku::Client.new(ENV['HEROKU_USERNAME'],
> > > > > > >> ENV['HEROKU_PASSWORD'])
> > > > > > >>                myapp = 
> > > > > > >> heroku.config_vars(ENV['HEROKU_APP'])["HEROKU_APP"]
> > > > > > >>                worker_count = WorkerCount.find(1)  # now I'm 
> > > > > > >> storing the current
> > > > > > >> number of active workers in a table that will always only have 
> > > > > > >> one
> > > > > > >> record.
> > > > > > >>                workers = worker_count.workers
> > > > > > >>                qty = workers + 1
> > > > > > >>                worker_count.workers = qty
> > > > > > >>                worker_count.save
> > > > > > >>                heroku.set_workers(myapp, qty)
> > > > > > >> end
>
> > > > > > >> In the heroku console, this runs smoothly until I try the last 
> > > > > > >> line,
> > > > > > >> to which I get this error:  TypeError: can't convert
> > > > > > >> RestClient::Payload::UrlEncoded into String
>
> > > > > > >> This line is formatted the same as LostBoy's workless gem, the
> > > > > > >> autoscaling tree of delayed_job, and 
> > > > > > >> Heroku-Delayed-Job-Autoscale.  I
> > > > > > >> must be missing something obvious (typical newbie, huh?)   ;)
>
> > > > > > >> Thanks again for any help,
> > > > > > >> Jim
>
> > > > > > >> On Jan 20, 9:16 am, Peter Haza <[email protected]> wrote:
> > > > > > >>> I've done autoscaling of workers
> > > > > > >>> here:https://github.com/phaza/Heroku-Delayed-Job-Autoscale
> > > > > > >>> It's actually more like auto-shutdown of a single workers, but 
> > > > > > >>> it works well
> > > > > > >>> in our environment.
>
> > > > > > >> --
> > > > > > >> You received this message because you are subscribed to the 
> > > > > > >> Google Groups "Heroku" group.
> > > > > > >> To post to this group, send email to [email protected].
> > > > > > >> To unsubscribe from this group, send email to 
> > > > > > >> [email protected].
> > > > > > >> For more options, visit this group 
> > > > > > >> athttp://groups.google.com/group/heroku?hl=en.
>
> > > > > > > --
> > > > > > > You received this message because you are subscribed to the 
> > > > > > > Google Groups "Heroku" group.
> > > > > > > To post to this group, send email to [email protected].
> > > > > > > To unsubscribe from this group, send email to 
> > > > > > > [email protected].
> > > > > > > For more options, visit this group 
> > > > > > > athttp://groups.google.com/group/heroku?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Heroku" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/heroku?hl=en.

Reply via email to