The gem is being used in production for over 6 months now, in a big-scale website (Gogobot), so I thought it’s time to put in some extra needed work, some major refactoring and to release 1.0.
1.0 is basically the same in the core functionality, I refactored big bits of the codebase, it’s much cleaner and more readable then before (still need to work quite a bit on code documentation)
Added the later method support for ActiveRecord models.
Added the loner support, now you can mark methods to be loners, meaning only a single instance of this method can exist in the queue at all times, this is super useful when a user does many actions that will result in say a cache clear for the user, there’s no reason to do a clear more then once. (and there are many more cases like this)
So, right off the README, here’s simple usage for this gem
So, now you can do this:
The best thing about perform_later (not new in this version) is that you can pass in any param, and it will get translated into JSON with no problem.
You can pass in AR objects, hashes, arrays, anything you need, there’s no need to rewrite your methods.
I would love your comments, feel free to contribute issues, pull requests, documentation or anything else.
Ruby/Rails project sometimes make it hard to find the source location of a method.
Sometimes, Duck typing, meta-programming and just plain bad design make it really hard to find where a method was defined and how.
Luckily, there’s an easy way around this.
So, here’s an example.
A few moments ago, I came across this line:
First thing I did (obviously) was going to the user class and searching for this method. Obvious enough (or this post would not exist) I could not find it.
I immediately realized it’s being defined by some cache mechanism we have.
So, I opened up a console and typed this:
And it returned
So, the method IS defined on the user somewhere, you can see exactly where like so:
This will give you an exact location where the method is defined, I found this line:
This trick saves me time, hope it will save you some browsing around helplessly, especially in bigger non-single-dev projects
EDIT: 12 APR 2012 10:51PM
I posted a link to this post in the dev chat room on Campfire.
Steve, had an awesome comment:
We are using Octopus gem in our application (Gogobot), this gem is used to connect to databases with master/slave architecture.
Just as a general warning, you may get some results like that. but if you follow the source location, it’s usually a very good hint of where the method is actually defined and in any case, I think those Proxy situations are rare.
Awesome comment nonetheless, so I though I might update the post with it.
EDIT: 12 APR 2012 11:01PM
Jonathan Jacksonreplied to me on twitter, he said, that if you are using Pry (which you should) you can actually do it even better.
if you open up the console and do:
This will open up the default editor (Vim in my case) in the exact location where the method is defined and you are able to edit it in place.
Another awesome comment that was worth a post update
There’s a lot of buzz going on about software development methodologies, people talking about Agile, Kanban, Pair, XP and more and more.
There’s not much people are talking about when it comes to a single developer.
I have been a consultant/developer for the past ~3 years or so, working from home for several clients both in Israel and abroad (US mainly).
During this time I gained tons of experience in knowing what works and what doesn’t, this may be specific to me, but I don’t think so, so I decided to share this knowledge. So… what am I doing to keep productive during the day?
The pomodoro technique I am using is simple, I have a small application running on my Mac constantly (there’s windows versions as well).
When I start work, I simply choose start pomodoro, input what I am going to work on and dive in.
Now, all that’s pretty standard, but I am using it with get-shit-done, so once I start a pomodoro, get-shit-done executes work mode.
This work mode shuts down all outer traffic to time-sinks like Facebook, Twitter, news sites, YouTube and many more.
The script is customizable so I keep changing what I want/need. Along side with shutting down the time sinks, I execute a “busy” mode on Skype and any IM I am using at the moment. This is completely automatic, you can see it in the following screenshots
As you can see, any pomodoro I do is going into “Things” which I can then look at my day and see where my time went, what did I accomplish during the day and so on (it has OmniFocus integration as well).
This may seem stupid so up high here, but it’s REALLY important. I found that in days where I drink and stay hydrated, I am much more productive, less tired and get a lot more done during the day.
Another benefit is that I need to visit the restroom quite often so I don’t slack around in the chair too much. I use an application for that as well, it sits in my top bar and reminds me to take 5 minute water breaks every hour. if you are wired in, you can just ignore that, but don’t ignore it too much, it’s not the point
I write down anything I need to do, and then I forget about it, I don’t keep my mind occupied with all I need to do, I look at the list during the day.
One important thing is that I set times for stuff
1-2pm => working on the cashier module
2:30-3:30pm => working on the master/slave @dirty variable
While of course, these 2 tasks don’t actually take an hour, it’s here just for an example :-).
Anything you need to remember during the day, write it down, than simply let it go, don’t keep you mind occupied about that.
I keep any blog post idea, stuff that come to mind on other project that are not currently in work order and more…
Knowing I have it written down saves me the trouble of having it in my brain, and I dedicate all my brain resources (which are slim to begin with) dedicated to my code.
I must say, I have tried any TODO app out there, the one that works best for me is a pen and a paper, I use Things as a history for my pomodoros and nothing more (usually)
Another possible controversial title in a “be productive” blog post
When I am TDD’ing my mind goes into a “small piece” mode, I think only about the next 2-3 steps in what I need to accomplish.
People (wrongly) think that TDD is time consuming and they get less done, I have proven it numerous times in the past that this is incorrect, people that TDD are often 2-3X more productive then others.
Just think about every time you open a browser to “test” something, it can be done in TDD while you save your file, and you can instantly see if you broke something else in the code you are not thinking about.
The right side code is test, left side is actual controller code
When you are not productive…
There are simply days when you are not productive on the actual things you need to get done, in these days I don’t try and force myself into it, I simply move to other exciting stuff for 20-30 minutes (sometimes more)
I do a TON of open source, I help people in groups, forums etc..
Sometimes, answering a question, gets me back into code mode and I can find myself wired in for 2-3 hours after it.
To sum up
I touched but a fraction of my work methodology.
The thing is, you need to find YOUR groove, you need to find your pace, the hours where you are productive, the things that excite you.
You may take some of what I said here, you may take all and you may take nothing, all I am saying is that regardless of where/how you work in the team, you can have your own thing going on.
You may work with Pivotal Tracker or Trajectory, but still maintain your TODO list for the next few hours (like I do).
Share your thoughts…
I would love to hear what you think in the comments and have a discussion.