Backburner rake task - NameError: undefined local variable or method - jobs

I'm starting up with Backburner to run some jobs in the background of my app. I've tried following the documentation under "Working Jobs", but I'm clearly doing something very obvious and very incorrect.
Gemfile:
gem 'backburner'
Rakefile:
require_relative 'config/application'
require 'backburner/tasks'
Rails.application.load_tasks
And then in the rails console:
rake backburner:work
(which I think will just run all pending, enqueued backburner jobs.)
But all I get is the error: NameError: undefined local variable or method 'work' for main:Object from (pry):1:in '__pry__'
I sorta know what pry does (I use it to throw binding.pry into my code to debug, but that's about it), but I have no idea how it might be causing this. Not to mention I'm still pretty weak on the whole jobs and rake task front in general.
Any help would be much appreciated!

Apparently I'm in the business of asking dumb questions, lately. I was passing a variable to my Backburner.enqueue that is an ID, so I expected it to be numerical, like so: #admin.id. This would have been fine if #admin was defined in the scope of the helper I'm calling my enqueue in, but I'm actually passing that variable to that helper method...which means #admin is not defined, which, guess what Daniel, means #admin.id is undefined. Which means that I'm hitting the job anyways (because no, Backburner is in fact NOT breaking), but I'm not getting the job enqueued the way I thought I was because I was passing an invalid property to it.
So it sort of turns out that the error I got looked completely unrelated to the issue, but there it is. Always pass the variables your methods are expecting, or else expect errors.
EDIT:
Also, I can't downvote my own post. I tried. It deserves it.
EDIT 2:
Turns out it's really hard/not supported to get beanstalkd going on Heroku. Der. Also should have checked that. I just liked how beanstalkd was handling some things and went with it before getting to deploy and realizing it was a no-go.
Instead, I went with Resque as suggested by Heroku. They also support Delayed Job (DJ), but noted it is pretty heavy and Resque is better.
All that to say, I finally got to where I needed to go with Resque, and because it was such a thing I made a little documentation to help me (and maybe any other sad soul who stumbles across this lame post) get background workers running on a Heroku-hosted Rails app in the future. Be warned: it really is a guide for dummies like me, since I had to puzzle out a lot of what now is fairly obvious to me. There are gaps in the Resque documentation that I've included, which really just boils down to being explicit about what certain things mean, and where things go.

Related

Initializer does not execute when models reload on Rails 3.1 development environment

We are currently using Ruby 1.9.3, Rails 3.1 (i know, we're working hard to upgrade all our applications).
We're using a module (let's call it 'OurModule' to add a method (let's call it 'OurAddOnMethod' to a model defined in a gem (let'd call that 'GemModel'). We have that module file living in the 'config/initializers' directory.
That file defines the module, and then calls this to include it in the model:
# Include the extension
GemModel.send(:include, OurModule)
When developing, things work well mostly, but periodically we will get an error that basically says "Undefined method 'OurAddOnMethod' in 'GemModel'". Restarting the server resolves the issue (for a while).
I'm assuming this is happening because the models are reloaded periodically with changes made in the development environment, and it appears that the initializers do not also get reloaded at that time..? It seems like this may not be the best way to set things up; it is quite frustrating to deal with.
Can anyone enlighten me on a better way to achieve this?
I ended up using wrapping the code in the following, and keeping it in initializers:
ActionDispatch::Callbacks.to_prepare do
# configure stuff or initialize
end
I feel really bad, i completely missed this question that seems to completely cover mine (linking to the answer that i used):
https://stackoverflow.com/a/8636163/287516

Debugging EXC_BAD_ACCESS

I've not worked on this project in quite some time.. When I left it some time in the iOS 8s it ran just fine, however.. on the latest XCode I'm getting many inconsistent EXC_BAD_ACCESS crashes. Now afaik it's requiring a deallocated object. However, the error is lacking where to look. This is quite a big project and like I say, the errors are inconsistent.
I've tried enabling zombie objects, as well as passing it as a starting parameter. However, this is leading me to no joy. I'm expecting something in the debug console with zombies enabled, is this right?
If anyone has any tips on how to find an easier way to debug this, as opposed to tinkering with everything and hoping it works..
EXC_BAD_ACCESS just means that your app is trying to access an invalid memory address. While it is oft caused be a deallocated object, that isn't always the case.
When the app crashes, there should be a crash log or backtrace. Post it as that'll provide clues.
Lovely; a crash entirely in framework code. Seeing as how it is SceneKit that is crashing, I would suggest replacing any graphic assets with new ones and see if that fixes it (even if it doesn't look right). Then check to make sure all of your geometries and layouts are correct.
Have you tried adding a global Exception or Symbolic breakpoint? Those usually help me 99% of the time when I encounter issues without any sort of backtrace.

Why is my vs2012 forcing extra parentheses

First, thank you for taking pity on me and reading this issue. I CANNOT for the life of me figure out what extension I might have installed that is causing this issue, but it is EXTREMELY cumbersome.
Whenever I begin to type code (VB I think it also occurs in C#), for example "For Each" once I hit the F it forces a set of parentheses. Which would look like F(), but because I keep typing it looks like F(or). This only occurs when coding inside code blocks like a function or a sub, but when I'm creating the function it does not occur. I've disabled any and all power tools and the like, or at least I'm 90% sure I've done this for all of them, and yet it still occurs.
I'm usually pretty proficient at digging about the net and finding the answer, but for this one I'm at a loss. There is just too many keywords involved, so all I see is non-related topics, or how to make the parentheses occur, not get rid of them.
If anyone can provide some steps to resolve this, I'm happy and eager to try them. It's just such a hassle to live with for right now.
If you think it is a Visual Studio extension, then start by disabling all of them and adding them back one at a time.
You can also run VS with the command line switched to disable features.
Devenv switches
The simple answer to the cause is the Codealike VS Extension. I logged a bug with them and hopefully they'll fix it soon

Random Crashing and weird console output

I wrote an entire app, and I was just about to submit it to the app store, and in my final testing, I went back and added a few releases to ensure proper memory management was observed. And since then, I keep getting these random crashes. I've tried removing some or all of the release calls, I've tried retaining objects. I cleaned the project. I used NSZombieEnabled and that also is not helping. All this to not avail.
Most of the time, the console says provides no help. Usually the app loads, I put NSLogs in viewDidLoad, viewDidAppear, and viewWillAppear, and they all show up in the console, then it crashes.
Sometimes I also get EXC_BAD_ACCESS (and I know what that means). But its occurring randomly. So this doesn't make sense to me. Thanks for any help possible. I've written this whole app, and spent months on it. So I'm really stuck. Thank you.
Have you tried Build --> Analyze? It will search your code for leaks and other useful things you might have missed. Try that and see if it finds anything for you.
I agree with Rudy. It sounds like you're releasing something that is still in use. I would go back to the version that was working and start adding the releases one at a time til it causes the crash. Slow but effective debugging.
When you say that you "sometimes" get EXC_BAD_ACCESS, what do you get the rest of the time? Where does the crash stack indicate you're crashing? What messages do you get?
Random crashes usually indicate a timing problem. A common cause is accessing things on multiple threads. Are you? It can also mean timing differences based on network traffic.
Make sure the console doesn't indicate an exception rather than a memory violation. Usually there's something in the console that will be useful.

Rails3 Engine helper over-ride

So I have a Rails 3.0 Engine (gem).
It provides a controller at app/controllers/advanced_controller.rb, and a corresonding helper at app/helpers/advanced_helper.rb. (And some views of course).
So far so good, the controller/helper/views are just automatically available in the application using the gem, great.
But I want to let the local application selective over-ride helper methods from AdvancedHelper in the engine (and ideally be able to call 'super'). That's a pretty reasonable thing to want to allow, right, a perfectly reasonable (and I'd think common) design?
Problem is, I can't seem to find any way to make it work. If the application defines it's own app/helpers/advanced_helper.rb (AdvancedHelper), then the one from the engine never gets loaded at all -- so that would work if you wanted to replace ALL the helper methods in there (without calling super), but not if you just want to over-ride one.
So that kind of makes sense actually, so I pick a different name. Let's call my local one ./app/helpers/local_advanced_helper.rb (LocalAdvancedHelper). This helper DOES get loaded, if I put a method in there that wasn't in the original engine's AdvancedHelper, it is available to views.
But if I put a method in there with the same name as one in the engine's AdvancedHelper... my local one NEVER gets called. It's like the AdvancedHelper (from engine) is earlier in the call chain than the LocalAdvancedHelper (from app). Indeed, if I turn on the debugger, and look at helpers.ancestors, that's exactly what's going on, they're in the reverse order I'd want in the ancestor chain. So AdvancedHelper (from engine) could theoretically call 'super' to call up to LocalAdvancedHelper (from app) -- but that of course wouldn't make a lot of sense to do, you'd never want to do that.
But what I would want to do... I can't do.
Anyone have any ideas, is there any way to provide this design, which seems perfectly reasonable to me, where an app can selectively over-ride a helper method from an Engine?
Anyone have any explanation of why it's working the way it is? I tried looking at actual Rails source code, but got lost pretty quick, the code around this stuff is awfully abstract split amongst a bunch of places.
This is pretty esoteric question, I'm pessimistic anyone will have any ideas, I hope you surprise me!
== Update
Okay, in order to understand what part of Rails code is being called where, I put a "def self.included ; debugger ; end" on each of my helpers, then in the debugger I can raise an exception to see a stack trace.
That still isnt' really helping me get to the bottom of it, the Rails code jumps all over the place and is pretty confusing.
But it's clear that a helper with the 'standard' name (ie WidgetHelper for WidgetController) is called by different rails code, to include in the 'master' view helper module for a given controller, than other helpers are. I'm wondering if I give the helper a different name, then manually include it in my controller with ("helper OtherNamedAdvancedHelper"), if that will change the load order.
We can use Module#class_eval to override.
In main app,
MountedEngineHelper.class_eval do
def advanced_helper
...
end
end
In this way other methods defined in engine helper are still available.
Thanks for your elaboration. I think this really is a problem. And it is still present in Rails 3.2.3, so I filed an issue.
The least-smelling workaround I came up with is to do a "half alias method chain":
module MountedEngineHelper
def advanced_helper
...
end
end
module MyHelper
def advanced_helper_with_extra_behavior
advanced_helper
extra_behavior
end
end
The obvious drawback is that you have to change your templates so that your helper is called. At least, you make the existence of extra behavior explicit there.
These release notes from Rails4 seem enticingly related to this problem, and potentially note it's been fixed:
http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#helpers-loading-order