Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Already have the .ruby-version and .ruby-gemset files with proper versions inside and this is the relevant line in my .bash_profile:

code:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Guess I'll try running the rvm get stable command.

EDIT: Ran the command, nothing changed.

Gmaz fucked around with this message at 15:29 on May 11, 2015

Adbot
ADBOT LOVES YOU

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home

Gmaz posted:

Already have the .ruby-version and .ruby-gemset files with proper versions inside and this is the relevant line in my .bash_profile:

code:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Guess I'll try running the rvm get stable command.

EDIT: Ran the command, nothing changed.

is RVM in your PATH ?
code:
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
You also don't necessarily need .ruby-version or .ruby-gemset; you can specify them in your Gemfile like this



I switched to doing it that way since that how Heroku looks for the version, and I just like having fewer dotfiles in a project

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Yeah I have all those things. I just ran bundle install again when it was complaining and now everything works. I guess it didn't install the gems for my gemset, but globally (into the rvm@globals folder, not globally on my system) instead the first time. Weird stuff, but it's resolved now.

Appreciate everyone's effort in trying to help me.

KoRMaK
Jul 31, 2012



If I wanted to spawn a process from my app that runs continuously, how would I do that and make sure it' stays running, or gets started again if its not? My rough draft is that I would spawn a SuckerPunch job that would just continuously run with a do while(true) loop, and sleep when it didn't have stuff to do.

kayakyakr
Feb 16, 2004

Kayak is true

KoRMaK posted:

If I wanted to spawn a process from my app that runs continuously, how would I do that and make sure it' stays running, or gets started again if its not? My rough draft is that I would spawn a SuckerPunch job that would just continuously run with a do while(true) loop, and sleep when it didn't have stuff to do.

What are you trying to do with this? If it's something that's going to be queuing, then use a queue system like resque. If it's something that's triggered to be a background task, use suckerpunch. If it's something timed, use whenever+chron.

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

KoRMaK posted:

If I wanted to spawn a process from my app that runs continuously, how would I do that and make sure it' stays running, or gets started again if its not? My rough draft is that I would spawn a SuckerPunch job that would just continuously run with a do while(true) loop, and sleep when it didn't have stuff to do.

You'll also want something like god/monit/whatever the new hotness is if you want to ensure that the process is constantly running.

KoRMaK
Jul 31, 2012



Thanks for the suggestions guys.

Yes, it's a queue that I'm building. So I'm checking out delayed job, resque etc. I started getting serious about delayed job, but I think I may have an issue with it. I need to limit how many of these things run per second. It doesn't seem like their is a way to manage that in delayed job. Is there a way I can tell it to only run X number of jobs per second?

If not, then I'd have to figure out a way to limit that.

necrotic
Aug 2, 2005
I owe my brother big time for this!

KoRMaK posted:

Thanks for the suggestions guys.

Yes, it's a queue that I'm building. So I'm checking out delayed job, resque etc. I started getting serious about delayed job, but I think I may have an issue with it. I need to limit how many of these things run per second. It doesn't seem like their is a way to manage that in delayed job. Is there a way I can tell it to only run X number of jobs per second?

If not, then I'd have to figure out a way to limit that.

Most queue systems give you a way to limit the number of workers, not a strict per/s limit. Once you figure out how long the task takes you can kind of limit the work per/s by lowering/raising the number of workers, but it won't be perfect.

I'm not sure about Delayed Job or Resque, but our job system lets you change queue reading strategies which would let you create a strategy that throttles when receiving messages. This would limit you to one process with an option for multiple threads, though you could do multi-process support with some work.

KoRMaK
Jul 31, 2012



It looks like I can hook into the reschedule method, or changing the run_at time. This means that the worker processes will have to know a little bit more than I wanted. Initially, I wanted the workers to know nothing about scheduling, and if they were spawned then it means they should just work. I designed a Manager to handle the worker spawning, and the manager would create a new worker if the limiter criteria was not exceeded.

Instead, I'll now upgrade the workers to check how many have run in the last second and last 24 hours, and if the limit has been reached then schedule them to run later. It looks like I can use the enqueue and before methods to help out with this.

necrotic, how do you write your strategies? What gem are you using?

necrotic
Aug 2, 2005
I owe my brother big time for this!
We use Chore, which we wrote internally and recently open sourced. Documentation is a little lacking, but the interface for the different types of strategies is pretty straight forward. We don't have anything that needs throttling internally so there's no mechanism built-in to handle it, but adding it to a custom Queue consumer wouldn't be all that difficult.

kayakyakr
Feb 16, 2004

Kayak is true
Reminder that ActiveJob was promoted to a first class citizen in the most recent Rails, so if you pick a gem to go with, you should probably pick one that integrates with activejob

necrotic
Aug 2, 2005
I owe my brother big time for this!

kayakyakr posted:

Reminder that ActiveJob was promoted to a first class citizen in the most recent Rails, so if you pick a gem to go with, you should probably pick one that integrates with activejob

Yeah, we should make an adapter for chore. Not a priority for us as we're still on 3.x :(

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through
I'm just about to use Resque, is there anything I should know about it or should I jump to something else before I'm in too deep?

necrotic
Aug 2, 2005
I owe my brother big time for this!

MasterSlowPoke posted:

I'm just about to use Resque, is there anything I should know about it or should I jump to something else before I'm in too deep?

Resque should be fine. I wouldn't use it at scale from past experiences, but if you go the ActiveJob route switching out backends is dead simple.

xenilk
Apr 17, 2004

ERRYDAY I BE SPLIT-TONING! Honestly, its the only skill I got other than shooting the back of women and calling it "Editorial".
I'm trying to wrap my head around the best solutions for multiple attachment from one form.

Is input file multiple (html5) + paperclip best/easiest way to go?

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home

necrotic posted:

Resque should be fine. I wouldn't use it at scale from past experiences, but if you go the ActiveJob route switching out backends is dead simple.

Yeah definitely use ActiveJob if you can, the abstraction is well worth it.

xenilk posted:

I'm trying to wrap my head around the best solutions for multiple attachment from one form.

Is input file multiple (html5) + paperclip best/easiest way to go?

That will work well enough if you don't need IE < v10. You'll need an attachment model that's has_many'd to your main model. The cleanest way would be something like this that just uses accepts_nested_attributes_for
http://www.tkalin.com/blog_posts/multiple-file-upload-with-rails-3-2-paperclip-html5-and-no-javascript/

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

MasterSlowPoke posted:

I'm just about to use Resque, is there anything I should know about it or should I jump to something else before I'm in too deep?

My understanding is that Sidekiq is a better Resque. I've been using Sucker Punch on a project because it doesn't require a separate worker process and the app is stable enough to not crash and lose pumas..

kayakyakr
Feb 16, 2004

Kayak is true

Cocoa Crispies posted:

My understanding is that Sidekiq is a better Resque. I've been using Sucker Punch on a project because it doesn't require a separate worker process and the app is stable enough to not crash and lose pumas..

Sucker Punch is the best for asynchronous tasks. Not the best for scheduling or a true queue. For scheduled stuff, I'd roll with whenever and put that in chron.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

kayakyakr posted:

Sucker Punch is the best for asynchronous tasks. Not the best for scheduling or a true queue. For scheduled stuff, I'd roll with whenever and put that in chron.

Right; the queue isn't persisted to disk anywhere, just held in the server process. If your server crashes, *poof* there goes your queue.

xtal
Jan 9, 2011

by Fluffdaddy
You're really missing out if you write Ruby without contracts.ruby. (Duck-)type safety and multimethods are very welcome additions to the language.

If you agree, also check out Crystal.

aunt jenkins
Jan 12, 2001

xtal posted:

check out Crystal.

:captainpop:
This is awesome! Exactly what I've been thinking over the last few days should exist. And it does, and it's actually pretty complete and good. Already got my first PR in :toot:

Pardot
Jul 25, 2001




I've been using crystal for the last month or so, and it's really fantastic.

KoRMaK
Jul 31, 2012



I don't get it. But I didn't get Rails either. Why is Crystal eye popping good?

necrotic
Aug 2, 2005
I owe my brother big time for this!

KoRMaK posted:

I don't get it. But I didn't get Rails either. Why is Crystal eye popping good?

If you like Ruby but want an actual type system, I guess. I wish the homepage had more info, and that the manual wasn't split into a million small sections.


Seriously, what the gently caress: http://crystal-lang.org/docs/syntax_and_semantics/comments.html

KoRMaK
Jul 31, 2012



necrotic posted:

If you like Ruby but want an actual type system, I guess. I wish the homepage had more info, and that the manual wasn't split into a million small sections.


Seriously, what the gently caress: http://crystal-lang.org/docs/syntax_and_semantics/comments.html
But it says that I never have to specify the type of a variable :confused:

Also, lol.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
http://en.wikipedia.org/wiki/Type_inference

Pardot
Jul 25, 2001




Yeah, there is global type inference so while everything is typed, you don't need to say types almost ever, except for empty arrays or hashes. The upside here is that you can easily track down branches that can potentially give you a nil at compile time.

Because it's all complied and can use all the optimization advances llvm has made, it is very fast. My postgres driver can decode 1MM date strings as postgres represents them, and create a Time object in 0.05s on my macbook air.

Also because it's all compiled (and not built on a pile of plan9 garbage) the lldb debugger works, but even more fun profiling tools work great. You can get source level heatmaps using the built-in os x instruments app. When you try that with an interpreted language like ruby, all you get is the VM. It's almost impossible to tell where your code is.


The C linking is super easy. This is literally all you need to have a minimal postgres driver that can execute queries
code:
@[Link(ldflags: "-lpq -I`pg_config --includedir` -L`pg_config --libdir`")]
lib LibPQ
  struct PGconn   end
  struct PGresult end
  fun connect       = PQconnectdb(conninfo : UInt8*) : PGconn*
  fun exec          = PQexec(conn : PGconn*, query : UInt8*) : PGresult*
  fun error_message = PQerrorMessage(conn : PGconn*) : UInt8*
end

conn = LibPQ.connect("postgres:///")
puts String.new(LibPQ.error_message(conn))

res = LibPQ.exec(conn, "insert into what values (now())")
puts String.new(LibPQ.error_message(conn))
You get most of the speed of C with a garbage collector, and most of the expressiveness of Ruby. You give up runtime dynamism, but like >99% of what that's used for in ruby is just at boot time configuration anyway. Moving that to compile time hasn't proven to be much of a burden at all. Yet anyway.

Yeah it's super new and the docs aren't great yet. A lot of the time I'm going through the source, but since that's all in rubycrystal it's not a huge deal. I hope this thing catches on, since it's super cool, but the real threat is that it never gets critical mass of adoption. The tech is there, the community not yet.

The Dreamer
Oct 15, 2013

Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn
Never mind. I finally got it to work.

The Dreamer fucked around with this message at 19:29 on May 22, 2015

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

This is everything I never knew I needed.

Peristalsis
Apr 5, 2004
Move along.
I ran a couple of migrations to add fields to two models on our existing app. So far, so good. Now when I write test cases, the new fields aren't recognized in the test environment. This is new - we've had this app for a couple of years now, and never have had this problem.

I'm assuming I now need to specify that the test environment should be included in rake db:migrate, but I don't know why this changed, and I'd like to know if this is a setting I can toggle somewhere.

The only way I can think that this could have changed is that I added a new gem to the end of the Gemfile and ran bundle install this morning, and maybe it updated some other gem that forced this setting, but I'm grasping at straws on that one.

KoRMaK
Jul 31, 2012



Is the schema that you are loading in test the right one?

Peristalsis
Apr 5, 2004
Move along.

KoRMaK posted:

Is the schema that you are loading in test the right one?

I'm not sure what you mean. How would I load a different one?

KoRMaK
Jul 31, 2012



I'm not sure how you would load a different one, but have you verified that the columns exist in test?

Sorry if this has already been covered.

Peristalsis
Apr 5, 2004
Move along.

KoRMaK posted:

I'm not sure how you would load a different one, but have you verified that the columns exist in test?

Sorry if this has already been covered.

The new columns didn't exist in test - that's why I was getting the error. I fixed it by running
code:
rake db:migrate RAILS_ENV=test
but I'm curious why I have to do this now, and have never had to do it before.

necrotic
Aug 2, 2005
I owe my brother big time for this!
The proper way to make sure your test database is correct is rake db:test:prepare. Not sure why it stopped happening on db:migrate for you, but use the test:prepare version instead.

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home
I've gotten that occasionally ever since they made the switch to keep test in-line with development. :shrug:

Peristalsis
Apr 5, 2004
Move along.

necrotic posted:

The proper way to make sure your test database is correct is rake db:test:prepare. Not sure why it stopped happening on db:migrate for you, but use the test:prepare version instead.

The Milkman posted:

I've gotten that occasionally ever since they made the switch to keep test in-line with development. :shrug:


Okay, thanks.

Here's another (unrelated) question.

I've made a user screen to enter login data which I then use to ssh to another computer and invoke a process there. I'm using the net-ssh gem, and having the user enter a login name in a text field, and a password in a password field.

If everything is perfect, it works. But, if I use the wrong password on the form and then submit, then the rails server stops and asks me to try again. Obviously, that isn't going to work in production. The server message says I should try HighLine or Termios libraries to suppress echoed text, and HighLine is suggested by the net-ssh gem documentation for automating terminal input, but it looks more like a library of commands to make CLI interaction easier, than something that prevents (or suppresses) being asked for a password. That is, it looks more applicable to a strict Ruby program than to a Rails app.

Does anyone have experience with this? I see three general approaches to this:
1) Find a way to make Rails deal automatically with the prompts that are coming up
2) Find a way to tell the ssh gem not to try again if the password is bad the first time
3) Maybe set a very short timeout param so that it's not a long wait, even if the password is wrong and the system wants to try it again

For now, I'm okay with an ugly hack, too. This is just a proof-of-concept that may or may not get past our IT group. (It seems they have some concerns about my code logging itself into random servers. Weirdos.)

Peristalsis fucked around with this message at 22:14 on May 28, 2015

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
What are you trying to do that you need something automating shell input? There's got to be a better way.

The Dreamer
Oct 15, 2013

Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn
I'm trying to randomly grab a field from a randomly selected record that is associated with another record. I see that I can do this by ordering and calling a Random function for whichever database I'm using. This is still a prototype app so I'll probably actually do this before I go to production. I found a different way to do this though and was wondering if it was actually a terrible idea. It works now but I'm not sure how it would scale over time with larger database tables.

I have 3 tables, Business, Types, and BusinessTypes. I'm doing a Business has_many Types though BusinessTypes association. What I'm trying to do right now is grab a random Business of a certain Type and grab an image url that is stored in the Business object. my current way of doing this is:

code:
type.businesses[rand(0...type.businesses.count)][:image]
Like I said this actually works but I'm just curious as to how it would scale. I know that just randomizing the order of the database files and then picking one can be really intense on the database with enough records but this way doesn't seem like it would be since I'm just randomly picking a number and then snagging that index out of the array of Business objects. I could be very wrong though especially if it has to create the whole array of objects every time its called. I just don't know enough about how ActiveRecord works to say one way or the other and wanted to know if someone could enlighten me.

Adbot
ADBOT LOVES YOU

Simone Poodoin
Jun 26, 2003

Che storia figata, ragazzo!



A quick look got me this article http://easyactiverecord.com/blog/2014/03/27/efficiently-getting-random-records-in-active-record/ and as you said the mysql rand method is pretty bad compared to picking a random id as he does, but that obviously doesn't work for you.

Now I'm curious too as to which queries your way would run, but don't have a rails setup on this computer. If I were you I would check the logs to see the actual queries. I would have probably picked a random from 0 to type.businesses.count and then do type.businesses.offset(rand) to get the business.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply