Coder Social home page Coder Social logo

hirefire's Introduction

HireFire.io - Autoscaling for your Heroku dynos (Hosted Service)

Note: This is not part of the open source variant

HireFire is a hosted service for auto-scaling both web- and worker dynos. The service supports practically any worker library across all programming languages through an abstract interface. For worker dynos it does provide a handful of convenient macros for calculating queue depths for various worker libraries (like Delayed Job, Resque, Qu, QueueClassic, Sidekiq, Bunny, Que).

In addition to autoscaling worker dynos, the service also autoscales web dynos. To do this we leverage the Heroku Logplex, allowing your application (again, in any programming language) to scale based on response times, rpm or dyno (cpu) load.

Aside from scaling based on variables such as queue depths, response times, rpm and load, you can also configure time ranges to schedule scaling operations on every minute of the week to meet your demands. You can even do this exclusively (without auto-scaling) if you wish.

For a mere $10/mo per app we've got you covered.

Check out the home page and docs for more information.


HireFire - Autoscaling for your Heroku workers (Open Source)

HireFire automatically scales your Heroku workers up- and down based on the size of queues. This library was specifically designed to work with Delayed Job and Resque.

If you have a small application that only processes maybe 2 hours worth of background jobs a month, and you're letting the worker run 24/7, it'll end up costing you $25/mo (assuming Standard-1X size). Rather than letting said worker run 24/7, HireFire can scale it down when you don't have jobs to process, resulting in a bill of $0.07/mo, rather than $25/mo.

If you have a medium-to-large application, this can result in significant cost savings depending on the nature of your application. Additionally, auto-scaling also ensures that your application doesn't build up a large backlog of jobs. Another benefit is the ability to quickly spin up a lot of workers for a short period of time to process jobs faster (in parallel), without the additional cost because Heroku Dynos are pro-rated to the second. So, whether you run 1 worker for 1 hour, or 6 dynos for 10 minutes, the cost is the same, but your jobs are processed 6 times faster.

Setting it up

In a Ruby on Rails environment, add the following:

Rails.root/Gemfile

gem 'rails'
# gem 'delayed_job' # uncomment this line if you use Delayed Job
# gem 'resque'      # uncomment this line if you use Resque
gem 'hirefire'

(The order is important: "Delayed Job" / "Resque" > HireFire)

Be sure to add the following Heroku environment variables so HireFire can manage your workers.

heroku config:add HIREFIRE_EMAIL=<your_email> HIREFIRE_PASSWORD=<your_password>

These are the same email and password credentials you use to log in to the Heroku web interface to manage your workers. Note that you can also use your Heroku API token in the HIREFIRE_PASSWORD environment variable. You can get your Heroku API token from the Heroku UI or via the CLI with heroku auth:token.

That's all you need to do to get the default configuration set up. You'll probably want to tailor the auto-scaling configuration to your application's requirements. Create an initializer (or similar configuration file that's loaded at boot-time) and configure HireFire's scaling behavior like so:

Rails.root/config/initializers/hirefire.rb

HireFire.configure do |config|
  config.environment      = nil # default in production is :heroku. default in development is :noop
  config.max_workers      = 5   # default is 1
  config.min_workers      = 0   # default is 0
  config.job_worker_ratio = [
      { :jobs => 1,   :workers => 1 },
      { :jobs => 15,  :workers => 2 },
      { :jobs => 35,  :workers => 3 },
      { :jobs => 60,  :workers => 4 },
      { :jobs => 80,  :workers => 5 }
    ]
end

Once done, you're ready to deploy to Heroku.

What the above configuration does: It ensures that you never have more than 5 workers at a time (config.max_workers = 5). And then we define an array of hashes that represent our job:worker ratio. In the above example we are basically saying:

  • Hire (= scale up) 1 worker if there are 1-14 queued jobs
  • Hire (= scale up) 2 workers if there are 15-34 queued jobs
  • Hire (= scale up) 3 workers if there are 35-59 queued jobs
  • Hire (= scale up) 4 workers if there are 60-79 queued jobs
  • Hire (= scale up) 5 workers if there are more than 80 queued jobs

Once all the jobs in the queue have been processed, it'll fire (= scale down) all the workers and start with a single worker the next time a new job gets queued. The next time the queue hits the 15 jobs mark, in which case the single worker isn't sufficient, it'll spin up the second worker, and at 35 jobs a third, etc.

If you prefer a more functional way of defining your job:worker ratio, you could use the following notation style:

HireFire.configure do |config|
  config.max_workers = 5
  config.job_worker_ratio = [
    { :when => lambda {|jobs| jobs < 15 }, :workers => 1 },
    { :when => lambda {|jobs| jobs < 35 }, :workers => 2 },
    { :when => lambda {|jobs| jobs < 60 }, :workers => 3 },
    { :when => lambda {|jobs| jobs < 80 }, :workers => 4 }
  ]
end

The above notation is slightly different, since now you basically define how many workers to hire when jobs < n. So for example if there are 80 or more jobs, it'll hire the max_workers amount, which is 5 in the above example. If you change the max_workers = 5 to max_workers = 10, then if there are 80 or more jobs queued, it'll go from 4 to 10 workers.

In a non-Ruby on Rails environment

Almost the same setup, except that you have to initialize HireFire yourself after Delayed Job or Resque is done loading.

require 'delayed_job'
# require 'delayed_job' # uncomment this line if you use Delayed Job
# require 'resque'      # uncomment this line if you use Resque
HireFire::Initializer.initialize!

(Again, the order is important: "Delayed Job" / "Resque" > HireFire)

If all goes well you should see a message similar to this when you boot your application:

[HireFire] Delayed::Backend::ActiveRecord::Job detected!

Worker / Mapper Support

HireFire currently works with the following worker and mapper libraries:

Suggestions, Bugs, Requests, Questions

View the issue tracker and post them there.

Contributors

Contributor Contribution
Dirk Gadsden ( dirk ) Implementing a more functional job/worker ratio notation using Lambda
Miguel Michelson Martinez ( michelson ) Allowing HireFire to initialize in non-Ruby on Rails environments
Nathaniel Bibler ( nbibler ) Ensures that HireFire gracefully handles RestClient exceptions
Sam Oliver ( samoli ) Adding the ability to specify a minimum amount of workers

Frequently Asked Questions

  • Question: Does it start workers immediately after a job gets queued?

    • Answer: Yes, once a new job gets queued it'll immediately calculate the amount of workers that are required and hire them accordingly.
  • Question: Does it stop workers immediately when there are no jobs to be processed?

    • Answer: Yes, every worker has been made self-aware to see this. Once there are no jobs to be processed, all workers will immediately be fired (shut down). For example, if you have no jobs in the queue, and you start cranking up your Workers via Heroku's web ui, once the worker spawns and sees it has nothing to do, it'll immediately shut itself down.
  • Question: How does this save me money?

    • Answer: According to Heroku's documentation, Workers (same as Dynos), are prorated to the second. For example, say that 10 jobs get queued and a worker is spawned to process them and takes about 1 minute to do so and then shuts itself down, theoretically you only pay $0.0008.
  • Question: With Delayed Job you can set the :run_at to a time in the future.

    • Answer: Unfortunately since we cannot spawn a monitoring process on the Heroku platform, HireFire will not hire workers until a job gets queued. This means that if you set the :run_at time a few minutes in the future, and these few minutes pass, the job will not be processed until a new job gets queued which triggers the chain of events. (Best to avoid using run_at with Delayed Job when using HireFire unless you have a mid-high traffic web application in which cause HireFire gets triggered enough times)
  • Question: If a job is set to run at a time in the future, will workers remain hired to wait for this job to be "processable"?

    • Answer: No, because if you enqueue a job to run 3 hours from the time it was enqueued, you might have workers doing nothing the coming 3 hours. Best to avoid scheduling jobs to be processed in the future.
  • Question: Will it scale down workers from, for example, 5 to 4?

    • Answer: No, I have consciously chosen not to do that for 2 reasons:
      1. There is no way to tell which worker is currently processing a job, so it might fire a worker that was busy, causing the job to be exit during the process.
      2. Does it really matter? Your jobs will be processed faster, and once the queue is completely empty, all workers will be fire anyway. (You could call this a feature! Since 5 jobs process faster than 4, but the cost remains the same cause it's all pro-rated to the second)
  • Question: Will running jobs concurrently (with multiple Worker) cost more?

    • Answer: Actually, no. Since worker's are pro-rated to the second, the moment you hire 3 workers, it costs 3 times more, but it also processes 3 times faster. You could also let 1 worker process all the jobs rather than 3, but that means it'll still cost the same amount as when you hire 3 workers, since it takes 3 times longer to process.
  • Question: Can I process jobs faster with HireFire?

    • Answer: When you run multiple jobs concurrently, you can speed up your processing dramatically. Normally you wouldn't set the workers to 10 for example, but with HireFire you can tell it to Hire 10 workers when there are 50 jobs (would normally be overkill and cost you A LOT of money) but since (see Q/A above) Workers are pro-rated to the second, and HireFire immediately fires all workers once all the jobs in the queue have been processed, it makes no different whether you have a single worker processing 50 jobs, or 5 workers, or even 10 workers. It processes 10 times faster, but costs the same.

Author / License

Released under the MIT License by Michael van Rooijen of HireFire.

hirefire's People

Contributors

ashervb avatar dirk avatar etrepat avatar igorbernstein avatar mrrooijen avatar nbibler avatar samoli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hirefire's Issues

Killing "rake jobs:work" process in local environment (development environment)

Hi,

I have configured config.environment = nil in my hirefire initializer. It is working great in heroku but I have a problem in my local environment. I usually run a "rake jobs:work" in the terminal, but hirefire is killing the process. The Noop strategy seems to be correctly set, but it kills the process anyway. Any tip on this?

Thanks for this tool by the way. Incredibly useful for us.

Time Range Bug

Whenever I try to set a time range for a dyno, I cannot save the page. Pressing the save button causes the loading circle to spin, but the page does not follow through with the save process.

If I do not set a time range, the page saves fine. This happening in Chrome and Firefox.

HireFire Hanging

I just pushed some updates to a Heroku app running HireFire and caused it to go on the fritz. It appears that requests that cause HireFire to do its thing are hanging because HireFire is busy hiring and firing workers back and forth:

2011-05-21T02:59:54+00:00 heroku[worker.1]: Starting process with command: `rake jobs:work`
2011-05-21T02:59:54+00:00 app[worker.1]: (in /app)
2011-05-20T19:59:55-07:00 heroku[worker.1]: State changed from starting to up
2011-05-21T03:00:00+00:00 app[worker.1]: [2011-05-20 20:00:00][HireFire] Delayed::Backend::ActiveRecord::Job detected!
2011-05-21T03:00:02+00:00 app[worker.1]: [2011-05-20 20:00:02][HireFire] Starting job worker!
2011-05-21T03:00:05+00:00 app[worker.1]: [2011-05-20 20:00:05][HireFire] All queued jobs have been processed. Firing all workers.
2011-05-20T20:00:05-07:00 heroku[api]: Set workers to 0 by [my email address]
2011-05-20T20:00:05-07:00 heroku[worker.1]: State changed from up to stopping
2011-05-21T03:00:05+00:00 heroku[worker.1]: Process exited
2011-05-21T03:00:06+00:00 app[web.1]: [2011-05-20 20:00:06][HireFire] Hiring more workers so we have 1 in total.
2011-05-20T20:00:07-07:00 heroku[api]: Set workers to 1 by [my email address]
2011-05-20T20:00:07-07:00 heroku[worker.1]: State changed from created to starting
2011-05-21T03:00:09+00:00 heroku[worker.1]: Starting process with command: `rake jobs:work`
2011-05-21T03:00:09+00:00 app[worker.1]: (in /app)
2011-05-20T20:00:10-07:00 heroku[worker.1]: State changed from starting to up
2011-05-21T03:00:15+00:00 app[worker.1]: [2011-05-20 20:00:15][HireFire] Delayed::Backend::ActiveRecord::Job detected!
2011-05-21T03:00:16+00:00 app[worker.1]: [2011-05-20 20:00:16][HireFire] Starting job worker!
2011-05-21T03:00:19+00:00 app[worker.1]: [2011-05-20 20:00:19][HireFire] All queued jobs have been processed. Firing all workers.
2011-05-20T20:00:19-07:00 heroku[api]: Set workers to 0 by [my email address]
2011-05-20T20:00:19-07:00 heroku[worker.1]: State changed from up to stopping
2011-05-21T03:00:19+00:00 heroku[worker.1]: Process exited
2011-05-21T03:00:20+00:00 app[web.1]: [2011-05-20 20:00:20][HireFire] Hiring more workers so we have 1 in total.
2011-05-20T20:00:21-07:00 heroku[api]: Set workers to 1 by [my email address]
2011-05-21T03:00:21+00:00 heroku[router]: Error H12 (Request timeout) -> POST [web address] dyno=web.1 queue=0 wait=0ms service=0ms bytes=0
2011-05-20T20:00:21-07:00 heroku[worker.1]: State changed from created to starting
2011-05-20T20:00:21-07:00 heroku[nginx]: POST /portfolio HTTP/1.1 | 72.177.88.112 | 747 | http | 503
2011-05-21T03:00:23+00:00 heroku[worker.1]: Starting process with command: `rake jobs:work`
2011-05-21T03:00:24+00:00 app[worker.1]: (in /app)
2011-05-20T20:00:25-07:00 heroku[worker.1]: State changed from starting to up
2011-05-21T03:00:30+00:00 app[worker.1]: [2011-05-20 20:00:30][HireFire] Delayed::Backend::ActiveRecord::Job detected!
2011-05-21T03:00:32+00:00 app[worker.1]: [2011-05-20 20:00:32][HireFire] Starting job worker!
2011-05-21T03:00:35+00:00 app[worker.1]: [2011-05-20 20:00:35][HireFire] All queued jobs have been processed. Firing all workers.
2011-05-20T20:00:36-07:00 heroku[api]: Set workers to 0 by [my email address]
2011-05-20T20:00:36-07:00 heroku[worker.1]: State changed from up to stopping
2011-05-21T03:00:36+00:00 heroku[worker.1]: Process exited
2011-05-21T03:00:37+00:00 app[web.1]: [2011-05-20 20:00:37][HireFire] Hiring more workers so we have 1 in total.
2011-05-20T20:00:37-07:00 heroku[api]: Set workers to 1 by [my email address]
2011-05-20T20:00:37-07:00 heroku[worker.1]: State changed from created to starting
2011-05-21T03:00:40+00:00 heroku[worker.1]: Starting process with command: `rake jobs:work`
2011-05-21T03:00:40+00:00 app[worker.1]: (in /app)
2011-05-20T20:00:44-07:00 heroku[worker.1]: State changed from starting to up
2011-05-21T03:00:46+00:00 app[worker.1]: [2011-05-20 20:00:46][HireFire] Delayed::Backend::ActiveRecord::Job detected!
2011-05-21T03:00:47+00:00 app[worker.1]: [2011-05-20 20:00:47][HireFire] Starting job worker!
2011-05-21T03:00:50+00:00 app[worker.1]: [2011-05-20 20:00:50][HireFire] All queued jobs have been processed. Firing all workers.
2011-05-20T20:00:51-07:00 heroku[api]: Set workers to 0 by [my email address]
2011-05-20T20:00:51-07:00 heroku[worker.1]: State changed from up to stopping
2011-05-21T03:00:51+00:00 heroku[worker.1]: Process exited
2011-05-21T03:00:52+00:00 app[web.1]: [2011-05-20 20:00:52][HireFire] Hiring more workers so we have 1 in total.
2011-05-20T20:00:52-07:00 heroku[api]: Set workers to 1 by [my email address]
2011-05-20T20:01:03-07:00 heroku[worker.1]: State changed from created to starting
2011-05-21T03:01:06+00:00 heroku[worker.1]: Starting process with command: `rake jobs:work`
2011-05-21T03:01:07+00:00 app[worker.1]: (in /app)
2011-05-20T20:01:07-07:00 heroku[worker.1]: State changed from starting to up
2011-05-21T03:01:13+00:00 app[worker.1]: [2011-05-20 20:01:13][HireFire] Delayed::Backend::ActiveRecord::Job detected!
2011-05-21T03:01:14+00:00 app[worker.1]: [2011-05-20 20:01:14][HireFire] Starting job worker!
2011-05-20T20:01:14-07:00 heroku[nginx]: POST /_heroku/console?session_action=create&session_id=810453 HTTP/1.1 | [my ip] | 747 | http | 503
2011-05-21T03:01:16+00:00 app[worker.1]: [2011-05-20 20:01:16][HireFire] All queued jobs have been processed. Firing all workers.
2011-05-20T20:01:17-07:00 heroku[api]: Set workers to 0 by [my email address]
2011-05-20T20:01:17-07:00 heroku[worker.1]: State changed from up to stopping
2011-05-21T03:01:17+00:00 heroku[worker.1]: Process exited

That's truncated. It continues after the HTTP request times out. It also managed to create around 17 workers by the time I stopped it, despite the log showing it toggles between 0 and 1.

I removed HireFire from my Gemfile and removed the config and pushed the change and everything works as expected, sans errors.

Here is my HireFire config:

HireFire.configure do |config|
  config.max_workers      = 20 # default is 1

  #10 jobs per worker // 1 worker per 10 jobs, up to 20 workers & 200 jobs
  worker_ratios = (0..200).step(10).inject([]) { |list, x| list << { :jobs => x, :workers => (x / 10) + 1 } }
  worker_ratios.first[:jobs] = 1
end

I would really appreciate some help solving this. I'm clueless as to what could be causing this, so any troubleshooting help would be much appreciated.

Nonzero min_workers causes continuous DB requests

I set min_workers=1. Now after the worker finishes processing the job (and delayed_jobs table is empty), it appears that the worker is continuously polling the database. Is this the desired behavior?

Log file:

2011-11-09T04:09:13+00:00 app[worker.1]: [2011-11-08 20:09:13][HireFire] 1 jobs processed at 0.2002 j/s, 0 failed ...
2011-11-09T04:09:13+00:00 app[worker.1]:   SQL (1.4ms)  SELECT COUNT(*) FROM "delayed_jobs" WHERE "delayed_jobs"."failed_at" IS NULL AND (run_at <= '2011-11-09 04:09:13.578721')
2011-11-09T04:09:13+00:00 app[worker.1]:   SQL (1.4ms)  SELECT COUNT(*) FROM "delayed_jobs" WHERE "delayed_jobs"."failed_at" IS NULL AND (run_at <= '2011-11-09 04:09:13.580942')
2011-11-09T04:09:15+00:00 app[worker.1]:   SQL (12.8ms)  SELECT COUNT(*) FROM "delayed_jobs" WHERE "delayed_jobs"."failed_at" IS NULL AND (run_at <= '2011-11-09 04:09:14.988993')
2011-11-09T04:09:16+00:00 app[worker.1]:   SQL (12.0ms)  SELECT COUNT(*) FROM "delayed_jobs" WHERE "delayed_jobs"."failed_at" IS NULL AND (run_at <= '2011-11-09 04:09:16.853224')
2011-11-09T04:09:16+00:00 app[worker.1]:   SQL (1.6ms)  SELECT COUNT(*) FROM "delayed_jobs" WHERE "delayed_jobs"."failed_at" IS NULL AND (run_at <= '2011-11-09 04:09:16.866073')
2011-11-09T04:09:18+00:00 app[worker.1]:   SQL (1.6ms)  SELECT COUNT(*) FROM "delayed_jobs" WHERE "delayed_jobs"."failed_at" IS NULL AND (run_at <= '2011-11-09 04:09:18.213203')
and so on...

Workers crashing

I'm having some odd errors since adding a min_workers parameter. The worker(s) start up, process the jobs in the queue, then crash without any error.

2011-06-09T19:15:03+00:00 heroku[worker.1]: State changed from crashed to created 2011-06-09T19:15:03+00:00 heroku[worker.1]: State changed from created to starting 2011-06-09T19:15:32+00:00 heroku[worker.1]: Starting process with command: rake jobs:work 2011-06-09T19:15:33+00:00 app[worker.1]: (in /app) 2011-06-09T19:15:37+00:00 heroku[worker.1]: State changed from starting to up 2011-06-09T19:15:40+00:00 app[worker.1]: [2011-06-09 12:15:40][HireFire] Delayed::Backend::ActiveRecord::Job detected! 2011-06-09T19:15:42+00:00 app[worker.1]: [2011-06-09 12:15:42][HireFire] Starting job worker! 2011-06-09T19:15:44+00:00 app[worker.1]: [Worker(host:50c28741-9e89-445d-86bc-9ea9dfa83fbd pid:1)] MailingJob completed after 1.1421 2011-06-09T19:15:46+00:00 app[worker.1]: [Worker(host:50c28741-9e89-445d-86bc-9ea9dfa83fbd pid:1)] MailingJob completed after 2.0813 2011-06-09T19:15:46+00:00 app[worker.1]: [2011-06-09 12:15:46][HireFire] 2 jobs processed at 0.6123 j/s, 0 failed ... 2011-06-09T19:15:47+00:00 app[worker.1]: [2011-06-09 12:15:47][HireFire] Starting job worker! 2011-06-09T19:15:49+00:00 heroku[worker.1]: Process exited 2011-06-09T19:15:50+00:00 heroku[worker.1]: State changed from up to crashed

If there's no jobs in the queue when I restart the worker, I get this:

2011-06-09T19:20:50+00:00 heroku[worker.1]: State changed from crashed to created 2011-06-09T19:20:50+00:00 heroku[worker.1]: State changed from created to starting 2011-06-09T19:21:08+00:00 heroku[worker.1]: Starting process with command: rake jobs:work 2011-06-09T19:21:08+00:00 app[worker.1]: (in /app) 2011-06-09T19:21:11+00:00 heroku[worker.1]: State changed from starting to up 2011-06-09T19:21:16+00:00 app[worker.1]: [2011-06-09 12:21:16][HireFire] Delayed::Backend::ActiveRecord::Job detected! 2011-06-09T19:21:18+00:00 app[worker.1]: [2011-06-09 12:21:18][HireFire] Starting job worker! 2011-06-09T19:21:21+00:00 app[worker.1]: [2011-06-09 12:21:21][HireFire] Starting job worker! 2011-06-09T19:21:23+00:00 heroku[worker.1]: Process exited 2011-06-09T19:21:24+00:00 heroku[worker.1]: State changed from up to crashed

and here's my hirefire.rb

if defined?(HireFire) HireFire.configure do |config| config.max_workers = 3 # default is 1 config.min_workers = 1 config.job_worker_ratio = [ { :jobs => 1, :workers => 1 }, { :jobs => 5, :workers => 2 }, { :jobs => 10, :workers => 3 } ] end end

If I remove the config_min_workers line then everything works as expected, but I'm missing that minimum worker I need to keep an eye on mailer jobs.

I still need to use rake jobs:work ?

Hi!

I started with HireFire the last week and have a simple question about it.

With HireFire I still need to use the rake jobs:work?

If yes. How I can use start it on background at Heroku?

Best regards!

queues

I know this is really a question.
But DJ and Resque all support Queues.. Does hirefire?
If it does everything in order then what's the point of Queues.

Also could you please create a page with all the potential settings.. I didn't notice one.

Worker gets killed before destroy was commited

When I use a postgresql database with hirefire min_workers set to 0 there is always a Job in the database that was processed but still locked and in the database.

I found that the following code is causing that behavior:

after_destroy 'self.class.environment.fire'

When I comment out that line it works like expected. The worker will get fired correctly after all jobs are done.

Is this after_destroy callback really needed? If yes, is it possible to exclude it when :local is used as environment?

My hirefire setup:

require 'hirefire'
HireFire.configure do |config|
  config.environment      = :local
  config.max_workers      = 1
  config.min_workers      = 0
end

Deploying with hirefire won't spin up dj worker

Hi,

I am trying to use hirefire gem to do autoscaling job, but no worker seems to run when a new job gets into delayed_job queue.
Is there anything wrong with my configuration ?
Am I missing something ?
My heroku stack: * cedar (beta)

  1. Gemfile:
    gem "delayed_job_active_record"
    gem 'hirefire'
  2. Procfile:
    web: bundle exec rails server -p $PORT
    worker: bundle exec rake jobs:work
  3. Config vars are set:
    HIREFIRE_EMAIL =>
    HIREFIRE_PASSWORD =>
  4. Initializer hirefire.rb:
    HireFire.configure do |config|
    config.max_workers = 5
    config.job_worker_ratio = [
    { :when => lambda {|jobs| jobs < 15 }, :workers => 1 },
    { :when => lambda {|jobs| jobs < 35 }, :workers => 2 },
    { :when => lambda {|jobs| jobs < 60 }, :workers => 3 },
    { :when => lambda {|jobs| jobs < 80 }, :workers => 4 }
    ]
    end
  5. When deploying to the server, the log indicates that firehire is well defined:
    2012-03-14T17:05:06+00:00 app[web.1]: => Call with -d to detach
    2012-03-14T17:05:06+00:00 app[web.1]: => Ctrl-C to shutdown server
    2012-03-14T17:05:06+00:00 app[web.1]: [2012-03-14 17:04:56][HireFire] Delayed::Backend::ActiveRecord::Job detected!

Though this setting works well when I manually scale a worker, it does not spin up a worker by itself.

Is there anything wrong in my server configuration that may cause this malfunctionality ?

Thanks,
Gilad

Is HireFire starting/stopping workers on Heroku when I run my app locally? (Test/Development)

My Procfile:

web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker:  bundle exec rake jobs:work

When I run foreman start:

17:02:07 web.1    | started with pid 10641
17:02:07 worker.1 | started with pid 10642
17:02:11 web.1    | I, [2013-03-28T17:02:11.861966 #10641]  INFO -- : Refreshing Gem list
17:02:22 web.1    | Connecting to database specified by database.yml
17:02:23 web.1    | [2013-03-28 17:02:23][HireFire] Delayed::Backend::ActiveRecord::Job detected!

BTW, I'm using Unicorn rather than Thin as I needed a separate process to build PDFs using PDFKit, but could I turn that into a delayed_job and then revert to Thin? Then I'd start the workers in a separate Terminal window which I think you recommend.

undefined method `environment' for #<Class:0x000000055da430>

Hi,

I am using hirefire on heroku. But after adding the gem and below code in the application .

HireFire.configure do |config|
  config.max_workers = 5
  config.job_worker_ratio = [
    { :when => lambda {|jobs| jobs < 15 }, :workers => 1 },
    { :when => lambda {|jobs| jobs < 35 }, :workers => 2 },
    { :when => lambda {|jobs| jobs < 60 }, :workers => 3 },
    { :when => lambda {|jobs| jobs < 80 }, :workers => 4 }
  ]
end

I am getting the below error in my heroku server logs and my application is running in qa environment.

2014-07-22T12:03:17.699704+00:00 app[worker.1]: [2014-07-22 12:03:17][HireFire] Starting job worker!
2014-07-22T12:03:17.714684+00:00 app[worker.1]:   Delayed::Backend::ActiveRecord::Job Update (4.0ms)   UPDATE "delayed_jobs" SET locked_by = null, locked_at = null WHERE (locked_by = 'host:b8f50f06-f60e-4333-a46e-391d247af156 pid:2') 
2014-07-22T12:03:17.715080+00:00 app[worker.1]: rake aborted!
2014-07-22T12:03:17.723572+00:00 app[worker.1]: undefined method `environment' for #<Class:0x000000055da430>
2014-07-22T12:03:17.723608+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/searchlogic-2.3.16/lib/searchlogic/named_scopes/conditions.rb:88:in `method_missing'
2014-07-22T12:03:17.723611+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/searchlogic-2.3.16/lib/searchlogic/named_scopes/association_conditions.rb:19:in `method_missing'
2014-07-22T12:03:17.723612+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/searchlogic-2.3.16/lib/searchlogic/named_scopes/association_ordering.rb:27:in `method_missing'
2014-07-22T12:03:17.723614+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/searchlogic-2.3.16/lib/searchlogic/named_scopes/ordering.rb:30:in `method_missing'
2014-07-22T12:03:17.723616+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/searchlogic-2.3.16/lib/searchlogic/named_scopes/or_conditions.rb:28:in `method_missing'
2014-07-22T12:03:17.723618+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/activerecord-2.3.18/lib/active_record/base.rb:2002:in `method_missing'
2014-07-22T12:03:17.723619+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/will_paginate-2.3.15/lib/will_paginate/finder.rb:170:in `method_missing_with_paginate'
2014-07-22T12:03:17.723621+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/hirefire-0.1.4/lib/hirefire/workers/delayed_job/worker.rb:38:in `block in start'
2014-07-22T12:03:17.723622+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/hirefire-0.1.4/lib/hirefire/workers/delayed_job/worker.rb:37:in `loop'
2014-07-22T12:03:17.723624+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/hirefire-0.1.4/lib/hirefire/workers/delayed_job/worker.rb:37:in `start'
2014-07-22T12:03:17.723626+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/delayed_job-2.0.7/lib/delayed/tasks.rb:13:in `block (2 levels) in <top (required)>'
2014-07-22T12:03:17.723627+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
2014-07-22T12:03:17.723629+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
2014-07-22T12:03:17.723631+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
2014-07-22T12:03:17.723632+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
2014-07-22T12:03:17.723634+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
2014-07-22T12:03:17.723636+00:00 app[worker.1]: /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
2014-07-22T12:03:17.723637+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
2014-07-22T12:03:17.723639+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
2014-07-22T12:03:17.723640+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
2014-07-22T12:03:17.723642+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
2014-07-22T12:03:17.723667+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
2014-07-22T12:03:17.723669+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
2014-07-22T12:03:17.723670+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
2014-07-22T12:03:17.723672+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
2014-07-22T12:03:17.723673+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
2014-07-22T12:03:17.723675+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
2014-07-22T12:03:17.723676+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
2014-07-22T12:03:17.723678+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
2014-07-22T12:03:17.723679+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/bin/rake:23:in `load'
2014-07-22T12:03:17.723681+00:00 app[worker.1]: /app/vendor/bundle/ruby/1.9.1/bin/rake:23:in `<main>'
2014-07-22T12:03:17.723686+00:00 app[worker.1]: Tasks: TOP => jobs:work
2014-07-22T12:03:17.725339+00:00 app[worker.1]: ** [NewRelic][07/22/14 12:03:17 +0000 b8f50f06-f60e-4333-a46e-391d247af156 (2)] INFO : Starting Agent shutdown
2014-07-22T12:03:17.829559+00:00 app[web.1]: NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
2014-07-22T12:03:17.829564+00:00 app[web.1]: Gem.source_index called from /app/vendor/bundle/ruby/1.9.1/gems/rails-2.3.18/lib/rails/gem_dependency.rb:21.
2014-07-22T12:03:19.052324+00:00 heroku[worker.1]: State changed from up to crashed

Could you please help me on this.

Thanks,
Hare Ram

Saving password on config

Hello,

I don't think that saving one's password on config is a good idea for an app that has collaborators. Is there any other way to use HireFire without saving my password on config?

Thank you,

Thawatchai

Is this still maintained?

There are a few PRs that need to be merged for this to continue to work in the current Heroku environment. I get this when doing a bundle install:

Post-install message from heroku-api:

‼️	The heroku-api gem will not work.
‼️	You must instead use the platform-api gem.
‼️	The heroku-api gem communicated with the Legacy API which has been disabled.
‼️	https://devcenter.heroku.com/changelog-items/118
Post-install message from heroku:
 !    The `heroku` gem has been deprecated and replaced with the Heroku Toolbelt.
 !    Download and install from: https://toolbelt.heroku.com
 !    For API access, see: https://github.com/heroku/heroku.rb

I see there are fixes for this ready to be merged.

undefined method `shutdown?' for #<Worker ......

I'm just trying to get this all working with resque, and more specifically reque_mailer locally before publishing to Heroku. When I run rake jobs:work I get the following

Resque::Job detected!
rake aborted!
undefined method `shutdown?' for #<Worker

I guess I'm missing something. Anyone able to help?

John

Doesn't seem to be working

I configured like this:

HireFire.configure do |config|
  config.max_workers      = 4
  config.job_worker_ratio = [
    { :jobs => 1,   :workers => 1 },
    { :jobs => 15,  :workers => 2 },
    { :jobs => 35,  :workers => 3 },
    { :jobs => 60,  :workers => 4 }
  ]
end

When I deployed I got this:

[2011-04-13 08:38:53][HireFire] Delayed::Backend::ActiveRecord::Job detected!

I see the following:

heroku ps --app trajectory          
Process       State               Command
------------  ------------------  ------------------------------
cron.1        idle for 3h         rake cron
web.1         up for 10m          thin -p $PORT -e $RACK_ENV -R $HER..
web.2         up for 10m          thin -p $PORT -e $RACK_ENV -R $HER..
web.3         up for 10m          thin -p $PORT -e $RACK_ENV -R $HER..
web.4         up for 10m          thin -p $PORT -e $RACK_ENV -R $HER..
worker.1      up for 10m          rake jobs:work
worker.2      up for 10m          rake jobs:work

And this:

>> Delayed::Job.count
=> 11

The 11 jobs contain failed jobs, which I've configured delayed job to keep.

Any help would be appreciated, thanks.

Doesn't work by default in Development

The current code seems to default the internal environment to Noop instead of local when not running on Heroku. I think this is the wrong default since it's a reasonable assumption that in development mode, most developers would still like their background jobs to run.

Unexpected error while processing request: uninitialized constant Delayed

Unexpected error while processing request: uninitialized constant Delayed

/app/vendor/bundle/ruby/2.1.0/gems/hirefire-resource-0.3.7/lib/hirefire/macro/delayed_job.rb:46:in `queue'
/app/config/initializers/hirefire.rb:3:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.1.0/gems/hirefire-resource-0.3.7/lib/hirefire/middleware.rb:57:in `call'
/app/vendor/bundle/ruby/2.1.0/gems/hirefire-resource-0.3.7/lib/hirefire/middleware.rb:57:in `block in dynos'
/app/vendor/bundle/ruby/2.1.0/gems/hirefire-resource-0.3.7/lib/hirefire/middleware.rb:56:in `each'
/app/vendor/bundle/ruby/2.1.0/gems/hirefire-resource-0.3.7/lib/hirefire/middleware.rb:56:in `inject'
/app/vendor/bundle/ruby/2.1.0/gems/hirefire-resource-0.3.7/lib/hirefire/middleware.rb:56:in `dynos'
/app/vendor/bundle/ruby/2.1.0/gems/hirefire-resource-0.3.7/lib/hirefire/middleware.rb:45:in `each'
/app/vendor/bundle/ruby/2.1.0/gems/thin-1.6.2/lib/thin/response.rb:96:in `each'
/app/vendor/bundle/ruby/2.1.0/gems/thin-1.6.2/lib/thin/connection.rb:114:in `post_process'
/app/vendor/bundle/ruby/2.1.0/gems/thin-1.6.2/lib/thin/connection.rb:53:in `process'
/app/vendor/bundle/ruby/2.1.0/gems/faye-websocket-0.7.2/lib/faye/adapters/thin.rb:40:in `process'
/app/vendor/bundle/ruby/2.1.0/gems/thin-1.6.2/lib/thin/connection.rb:39:in `receive_data'
/app/vendor/bundle/ruby/2.1.0/gems/faye-websocket-0.7.2/lib/faye/adapters/thin.rb:44:in `receive_data'

Workers Not Being Fired

Working on adding HireFire to my application, and it doesn't seem to be firing the workers after the jobs are complete. I've checked the Delayed::Job.new.jobs and it's set to 0 (zero) after the job is ran, but the work stays online. I've waiting as long as five minutes and HireFire never seems to fire the worker. I'm using the example initializer to initialize HireFire in the rails app. Below is an excerpt from my log.

Here is my Heroku app starting up:

2011-07-02T18:53:55+00:00 heroku[web.1]: Unidling
2011-07-02T18:53:55+00:00 heroku[web.1]: State changed from down to created
2011-07-02T18:53:55+00:00 heroku[web.1]: State changed from created to starting
2011-07-02T18:54:04+00:00 heroku[web.1]: Starting process with command: `thin -p 5963 -e production -R /home/heroku_rack/heroku.ru start`
2011-07-02T18:54:06+00:00 app[web.1]: [2011-07-02 11:54:06][HireFire] Delayed::Backend::ActiveRecord::Job detected!
2011-07-02T18:54:06+00:00 app[web.1]: >> Thin web server (v1.2.6 codename Crazy Delicious)
2011-07-02T18:54:06+00:00 app[web.1]: >> Maximum connections set to 1024
2011-07-02T18:54:06+00:00 app[web.1]: >> Listening on 0.0.0.0:5963, CTRL+C to stop
2011-07-02T18:54:07+00:00 heroku[web.1]: State changed from starting to up

You'll notice that HireFire appears to start just fine.

And here is the log from running the jobs

2011-07-02T19:21:00+00:00 app[web.1]: [2011-07-02 12:21:00][HireFire] Hiring more workers so we have 1 in total.
2011-07-02T19:21:00+00:00 heroku[api]: Set workers to 1 by [email protected]
2011-07-02T19:21:01+00:00 heroku[worker.1]: State changed from created to starting
2011-07-02T19:21:08+00:00 heroku[worker.1]: State changed from starting to up
2011-07-02T19:21:41+00:00 heroku[router]: POST liveshow-test.heroku.com/_heroku/console dyno=web.1 queue=0 wait=0ms service=84ms status=200 bytes=18
2011-07-02T19:23:10+00:00 app[worker.1]: [Worker(host:46b4eb05-8577-4c4c-86d0-08cd42f4a958 pid:1)] acquired lock on Postoffice.deliver_welcome_normal_user
2011-07-02T19:23:10+00:00 app[worker.1]: Sent mail to [[email protected]]
2011-07-02T19:23:10+00:00 app[worker.1]: [Worker(host:46b4eb05-8577-4c4c-86d0-08cd42f4a958 pid:1)] Postoffice.deliver_welcome_normal_user completed after 0.4504
2011-07-02T19:23:10+00:00 app[worker.1]: [Worker(host:46b4eb05-8577-4c4c-86d0-08cd42f4a958 pid:1)] 1 jobs processed at 2.1400 j/s, 0 failed ...
2011-07-02T19:26:41+00:00 app[worker.1]: [Worker(host:46b4eb05-8577-4c4c-86d0-08cd42f4a958 pid:1)] acquired lock on Postoffice.deliver_welcome_normal_user
2011-07-02T19:26:41+00:00 app[worker.1]: Sent mail to [[email protected]]
2011-07-02T19:26:42+00:00 app[worker.1]: [Worker(host:46b4eb05-8577-4c4c-86d0-08cd42f4a958 pid:1)] Postoffice.deliver_welcome_normal_user completed after 0.4393
2011-07-02T19:26:42+00:00 app[worker.1]: [Worker(host:46b4eb05-8577-4c4c-86d0-08cd42f4a958 pid:1)] 1 jobs processed at 2.2234 j/s, 0 failed ...

What I'm doing to test, is I go into the console and I fire off a mailer to send an email to a test email address. Since my mailers are set to delay delivery they go through delayed jobs. So firing off a mailer from the console queues a delayed job which appears to hire the worker just fine. However, that worker is never fired. I either have to set the worker count to 0 (zero) via the heroku gem or log into the website and set it there to turn the worker off.

Sidekiq?

Any plans for sidekiq support?

undefined method `>' for nil:NilClass

Hi,

first of all, I really like hirefire, good job, congratulations.

I've been using HireFire for almost 2 months and everything worked fine until last night. I'm pasting the whole error trace, but basically, as I've been checking in the source files, HireFire has the variable 'workers' as nil in some moment and it's not able to compare it to min_workers in order to fire all the hired workers.

My context is simple: a cron is executed and if it finds a potential task to execute, it is enqueued to delayed_job, and in that moment the needed workers are hired by HireFire.

I'd like to know how it's possible to unknow the number of current workers, and how I can avoid this context. Meanwhile, I've forked the develop branch and modified that with a simple condition so that it never happens again.

Thank you very much for your support. This is the whole trace:

{undefined method >' for nil:NilClass /app/.bundle/gems/ruby/1.8/gems/hirefire-0.1.3/lib/hirefire/environment/base.rb:168:infire'
/app/.bundle/gems/ruby/1.8/gems/activesupport-3.0.0/lib/active_support/callbacks.rb:415:in _run_destroy_callbacks' /app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.0/lib/active_record/callbacks.rb:260:indestroy'
/app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.0/lib/active_record/transactions.rb:232:in destroy' /app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.0/lib/active_record/transactions.rb:289:inwith_transaction_returning_status'
/app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in transaction' /app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.0/lib/active_record/transactions.rb:204:intransaction_without_trace_ActiveRecord_self_name_transaction'
/app/vendor/plugins/rpm/lib/new_relic/agent/method_tracer.rb:394:in transaction' /app/vendor/plugins/rpm/lib/new_relic/agent/method_tracer.rb:193:intrace_execution_scoped'
/app/vendor/plugins/rpm/lib/new_relic/agent/method_tracer.rb:389:in transaction' /app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.0/lib/active_record/transactions.rb:287:inwith_transaction_returning_status'
/app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.0/lib/active_record/transactions.rb:232:in destroy' /app/.bundle/gems/ruby/1.8/gems/delayed_job-2.1.4/lib/delayed/worker.rb:121:inrun'
/usr/ruby1.8.7/lib/ruby/1.8/benchmark.rb:308:in realtime' /app/.bundle/gems/ruby/1.8/gems/delayed_job-2.1.4/lib/delayed/worker.rb:119:inrun'
/app/.bundle/gems/ruby/1.8/gems/delayed_job-2.1.4/lib/delayed/worker.rb:177:in reserve_and_run_one_job' /app/.bundle/gems/ruby/1.8/gems/delayed_job-2.1.4/lib/delayed/worker.rb:104:inwork_off'
/app/.bundle/gems/ruby/1.8/gems/delayed_job-2.1.4/lib/delayed/worker.rb:103:in times' /app/.bundle/gems/ruby/1.8/gems/delayed_job-2.1.4/lib/delayed/worker.rb:103:inwork_off'
/app/.bundle/gems/ruby/1.8/gems/hirefire-0.1.3/lib/hirefire/workers/delayed_job/worker.rb:42:in start' /usr/ruby1.8.7/lib/ruby/1.8/benchmark.rb:308:inrealtime'
/app/.bundle/gems/ruby/1.8/gems/hirefire-0.1.3/lib/hirefire/workers/delayed_job/worker.rb:41:in start' /app/.bundle/gems/ruby/1.8/gems/hirefire-0.1.3/lib/hirefire/workers/delayed_job/worker.rb:37:inloop'
/app/.bundle/gems/ruby/1.8/gems/hirefire-0.1.3/lib/hirefire/workers/delayed_job/worker.rb:37:in start' /app/.bundle/gems/ruby/1.8/gems/delayed_job-2.1.4/lib/delayed/tasks.rb:9 /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:636:incall'
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:636:in execute' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:631:ineach'
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:631:in execute' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:597:ininvoke_with_call_chain'
/usr/ruby1.8.7/lib/ruby/1.8/monitor.rb:242:in synchronize' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain'
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:583:in invoke' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2051:ininvoke_task'
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2029:ineach'
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling'
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in top_level' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2001:inrun'
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:1998:inrun'
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/bin/rake:31
/usr/ruby1.8.7/bin/rake:19:in `load'
/usr/ruby1.8.7/bin/rake:19

Keeping worker idle for specific amount of time

I use hirefire-gem with DJ 3 on heroku cedar-stack and it is working pretty good in terms of hiring/firing but performance of the job execution is terrible (probably herokus fault). firing up the background job and seeing the results in the UI takes about 5 -8 seconds locally and about 25-30 seconds (!) on heroku.

Processing time of the jobs is about the same locally/deployed but hiring workers (scaling, up, starting, ...) seems to take a lot of time. (has anyone the same issue? and probably a solution?)

I was thinking to fire up a worker a little bit in advance and then keep it up and grab the (anticipated) job. So my question is if it is possible to specifiy a time where to keep the worker up, e.g. 30 seconds.

Thanks a lot & thanks for the great gem. Really appreciate your work!
Best, Phil

EDIT: ok, I see, this is probably more of a discussion than a real issue. Hope it's okay.

Question: Optimal Hire/Fire Strategy

Given the per-second metering of heroku workers that you pont out,

I was curious if you would agree with the statement that the optimal hire/fire strategy is to scale every queued job with a new worker:

config.job_worker_ratio = [
      { :jobs => 1,  :workers => 1 },
      { :jobs => 2,  :workers => 2 },
      { :jobs => 3,  :workers => 3 },
      { :jobs => 4,  :workers => 4 },
      { :jobs => 5,  :workers => 5 }
]

etc.

and if not, why not.

How to confirm hirefire is working?

I'm trying to integrate hirefire with a Rails 2.3.11 app, and delayed_job 2.0.5 on Heroku (obviously).

When I queue a task using Delayed::Job.queue it gets saved to the database, but HireFire is not starting any workers.

I've got the ./config/initializers/hirefire.rb setup, and can confirm via the console that it is setup. I also have the HIREFIRE_EMAIL and HIREFIRE_PASSWORD environment variables configured.

But I don't see any hirefire related messages in the logs and no workers are spinning up.

If I manually spin up workers, the jobs are completed, but the workers are not automatically "fired".

Is there a way to confirm hirefire is working? It would be nice to have a "verbose" logging option or something to help troubleshoot.

Also what versions of delayed_job are supported?

Development log is endless when using thin

First of all: Good job on the gem: I have tested it for a short time in heroku, but is working great.

I have a question on development though. I am using thin as my development server and the development log starts growing a lot with lines like this about every second:

SQL (0.3ms) SELECT COUNT() FROM "delayed_jobs" WHERE "delayed_jobs"."failed_at" IS NULL AND (run_at <= '2011-07-15 01:03:30.589528')
SQL (0.3ms) SELECT COUNT(
) FROM "delayed_jobs" WHERE "delayed_jobs"."failed_at" IS NULL AND (run_at <= '2011-07-

Which makes it very hard to see the regular output from web requests.

Is there a work around for this?

Thanks a lot!

jobs is not firing on heroku staging server

Hi,

i'm using gem "delayed_job_active_record" with hire fire on heroku to run jobs in background.i have also set heroku envirnoment variable using my heroku account. My sequence in gem file is below

   gem 'delayed_job_active_record'
   gem 'daemons'
   gem 'hirefire'

it is working in local envirnoment in development as production as well. But jobs not firing on heroku from delayed job table. First i try with no config file hirefire.rb in intilizer but no succes. After i add and put this code below.

           HireFire.configure do |config|

             if Rails.env.production?
              config.max_workers = 5 # default is 1
              config.min_workers = 0 # default is 0
              config.job_worker_ratio = [
               {:jobs => 1, :workers => 1},
               {:jobs => 15, :workers => 2},
               {:jobs => 35, :workers => 3},
               {:jobs => 60, :workers => 4},
               {:jobs => 80, :workers => 5}
              ]
        end
      end

but no success. Although hirefire is also loading see screen shot below also

Screenshot from 2013-02-19 12:21:00

this info might help

      kashif@kashif-HP-ProBook-4520s:~/rails/alisa/metnet$ heroku ps:scale  --app gentle-gorge-9319
          !    Usage: heroku ps:scale web=2 worker+1
      kashif@kashif-HP-ProBook-4520s:~/rails/alisa/metnet$  
      kashif@kashif-HP-ProBook-4520s:~/rails/alisa/metnet$ heroku ps  --app gentle-gorge-9319
          === web: `bundle exec rails server -p $PORT`
          web.1: up for 1h

for now i'm using this command to run delayed job

        heroku run rake jobs:work --app gentle-gorge-9319

but when close terminal on linux then delayed job not fired. Also nohup is not working on heroku.

Thanks

support for the new cedar stack

Scaling on the new cedar stack is via the heroku scale commoand, and it doesnt seem to work with the current implementation.

Heroku not hire/firing

I've installed the gem, and am using the default initializer file.

When I deployed, I saw:

...
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       [2011-10-27 03:52:37][HireFire] Delayed::Backend::ActiveRecord::Job detected!
       /usr/local/bin/ruby /tmp/build_6i5qq0q09fif/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
       [2011-10-27 03:52:49][HireFire] Delayed::Backend::ActiveRecord::Job detected!
-----> Rails plugin injection
...

Watching the logs of my jobs running (I scaled to worker=1 manually) the only mention of hirefire working is the occasional "100 jobs complete" message:

2011-10-27T04:10:10+00:00 app[worker.1]: [2011-10-27 04:10:10][HireFire] 100 jobs processed at 1.5143 j/s, 17 failed ...

I have well over 500 jobs in the queue, but I'm still only running one worker... =^[

worker not being hired unless manual rake

HireFire is able to detect my Resque Jobs:

2011-09-23T05:02:50+00:00 heroku[web.1]: Starting process with command `thin -p 44349 -e staging -R /home/heroku_rack/heroku.ru start`
2011-09-23T05:02:51+00:00 heroku[web.1]: Process exited
2011-09-23T05:02:58+00:00 app[web.1]: [2011-09-23 13:02:58][HireFire] Resque::Job detected!
2011-09-23T05:03:02+00:00 app[web.1]: >> Thin web server (v1.2.11 codename Bat-Shit Crazy)
2011-09-23T05:03:03+00:00 heroku[web.1]: State changed from starting to up

but then it just sits there until I run heroku rake jobs:work

2011-09-23T05:06:51+00:00 heroku[rake.6]: State changed from created to starting
2011-09-23T05:06:56+00:00 heroku[rake.6]: State changed from starting to up
2011-09-23T05:07:11+00:00 heroku[api]: Set workers to 1 by <my_email@address>
2011-09-23T05:07:12+00:00 heroku[worker.1]: State changed from created to starting
2011-09-23T05:07:17+00:00 heroku[worker.1]: Starting process with command `rake jobs:work`
2011-09-23T05:07:17+00:00 app[worker.1]: (in /app)
2011-09-23T05:07:18+00:00 heroku[worker.1]: State changed from starting to up
...

and then it works fine, firing the worker when done. if a job is subsequently queued while the rake process is still alive, HireFire does its job, but stops again when the rake process is killed.

any ideas?

edit: Rails 3.0.10 on Bamboo

undefined local variable or method `name' Delayed::Worker

running:
rails 2.3.8
delayed_jobs 1.7.0 (plugin)
hirefire 0.1.1 (gem)

When running rake jobs:work on local I am getting an error:

rake jobs:work --trace

(in /Users/raulmpadilla/projects/thepista)
** Invoke jobs:work (first_time)
** Invoke merb_env (first_time)
** Execute merb_env
** Invoke environment (first_time)
** Execute environment
** Execute jobs:work
[2011-04-18 19:27:21][HireFire] Starting job worker!
rake aborted!
undefined local variable or method name' for #<Delayed::Worker:0x59a02b8 @quiet=nil> /opt/local/lib/ruby/gems/1.8/gems/hirefire-0.1.1/lib/hirefire/workers/delayed_job/worker.rb:63:instart'
/Users/raulmpadilla/projects/thepista/vendor/plugins/delayed_job/lib/tasks/tasks.rb:13
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in call' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:inexecute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in each' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:inexecute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in invoke_with_call_chain' /opt/local/lib/ruby/1.8/monitor.rb:242:insynchronize'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in invoke_with_call_chain' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:ininvoke'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in invoke_task' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:intop_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in each' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:intop_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:intop_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in run' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in run' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31 /opt/local/bin/rake:19:inload'

HireFire not working on Cedar?

I'm upgrading a Bamboo 3.0 app to Cedar 3.2, and everything is working except HireFire.

I've added the correct environment vars. I can't figure this out. What am I missing:

Here is the console session showing that HireFire is live, but not doing anything.

Is there at least a way to get an error report of some kind? I can't tell what's going on...

https://gist.github.com/pixelterra/4733448

Why is my worker still running? (aka Confused about relation among hirefire, Procfile and foreman)

My Heroku-based app has a Procfile that reads:

# file: Procfile
web: bundle exec rails server thin -p $PORT
worker: bundle exec rake jobs:work

I've bundled the hirefire gem, and when I start my app, it appears that HireFire is running:

$ git push heroku master
...
       [2012-08-31 20:51:34][�[32mHireFire�[0m] Delayed::Backend::ActiveRecord::Job detected!
...

Looking at the processes (with no web activity that would have requested a DelayedJob), my worker task hasn't been fired -- it's been running for 16 minutes:

heroku ps
=== web: `bundle exec rails server thin -p $PORT`
web.1: up for 16m
=== worker: `bundle exec rake jobs:work`
worker.1: up for 16m

Heroku API Rate Limiting

I'm using delayed job in rails with HireFire. I have a delayed job that queues a few thousand other delayed jobs and every time I queue a new one HireFire tries to scale the workers to 1.

Is there any way I can I prevent this from happening on a case by case basis? Like

HireFire.stop_autoscaling_for_a_minute
[queue all my jobs]
HireFire.ok_go_ahead_and_autoscale

Or maybe since it's already in a worker it doesn't need to call to the Heroku API at all?

Throwing Resque::DirtyExit when running hirefire in development

Could someone help me with this? I am missing something?
I'm just trying to run Firehire with Resque on localhost and the jobs gets failed with the Resque::DirtyExit error.
What should I do?

My hirefire.rb

HireFire.configure do |config|
  config.environment      = :local # default in production is :heroku. default in development is :noop
  config.max_workers      = 1   # default is 1
  config.min_workers      = 0   # default is 0
end

Thanks!

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.