opposite action to Sidekiq::ScheduledSet.new.clear - ruby-on-rails

This is a very straight and simple question:
Is there any way to populate o re create the ScheduledSet jobs? I mean something opposite to Sidekiq::ScheduledSet.new.clear ?
Or, can I run average_scheduled_poll_interval from the rails console?

After a while, I found something similar to what I was looking for: basically, what I wanted is that the workers to reload the changes in the source code, and found this answer in the FAQ page.
It needs an extra gem, but it does the job.

Related

Manually trigger a post_updated webhook in Discourse

I’m looking to make a change to the raw data for a bunch of my Discourse posts in a rake task and then re-cook the result.
When this happens I also want to trigger the webhook for post_updated
What’s the best practice way to achieve this?
This has been answered in another forum, thanks to Guo Xiang Tan for the answer.
From your rails console, you can run WebHook.enqueue_post_hooks(:post_edited, post). Make sure Sidekiq is running though.

clarifying rails find method

I call the rails find method a lot during my view. Is this a generally accepted good practice? I'm leaning towards no, but why? Does find call the database each time? Does it cache the result anywhere? I looked up the ruby/rails docs on find but they didn't specify if it actually made a call to the database each time or not.
No, it is not a good idea to call find from the view. It is the job of a controller to load and assemble all the data that a view will need, and pass it to the view for presentation to the user.
Repeated calls to find for the same object should be cached by Rails, so it wouldn't hit the database each time, unless the arguments or other parameters were different.
A realtively easy way to test this would be to fire up a terminal and run rails c. In the console, run the code that returns tplangroup and play with it in the console. You should be able to see database call in the development console.
Based on my experience (not at a computer with rails right now) I think it would hit the database in each of these calls, unless you created tplangroup using the .includes(:tplan) for eager loading.
Hope this helps

modify single user info in rails

I'm using devise. I modified the user fields with no problem. I need to access certain users, and modify their info. For example, let's say that the user "pete" should have the field "type" changed to "active". How do I do that? it should be just accessing the database and modify that field, but I can't make it work. I mean, there are tools to modify databases, but what is the rails way to do it?
I don't need a tool or script or modify the code, it's a small database and very few changes. Once I understand this, I may do something more general.
The typical rails way to operate on your data like this is to write custom rake tasks. The great Ryan Bates has a great screencast on the topic as well: http://railscasts.com/episodes/66-custom-rake-tasks.
If you do not want to do that, and the fixes you are making are really small, then you can do them via the rails console. More on that here: http://railsonedge.blogspot.in/2008/05/intro-to-rails-console.html
If you need the actual code of how to do that, it may look like this:
pete = User.find_by_name('pete')
pete.update_attributes(:type, 'active')

Solutions for cron jobs in rails3

I'm trying to log some data daily, automatically in my rails app. I was wonder if anyone knows a good solution for this? I found https://github.com/javan/whenever, but I wanted to make sure I knew of all the options before I chose.
Thanks!
Elliot
I really like whenever - it's a great Gem and I have used it in production.
There is also a good Railscasts episode about it:
http://railscasts.com/episodes/164-cron-in-ruby

rails smart collection

What are rails smart collections?
If I am trying to build a view that presents most popular articles, top 10 products, recent comments (i.e a snapshot of recent updates to a variety of models in one view), would I be using a smart collection?
Would I be updating it via something like delayed job? Use some sort of fragment caching?
What's the best way of doing this?
Thanks
I've never heard of 'smart collections'. That reference to them in the delayed_jobs docs seems to be the only one out there. It would probably be better to email the author, he might have been referring to something that exists only in his head :)

Resources