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
A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Maista posted:

First order of business: upgrade Ruby and Rails I've looked at the changes from Ruby 1.9.3 to 2.4 (it seems sensible to keep using latest version) and they don't seem too bad, but the changes to Rails might be worse. Since the app is relatively simple, I'm going to suggest starting from a new Rails 5 application and just migrating models one by one until an issue appears (fixing any antipatterns I spot along the way) and then fixing them one by one. I'm going to spend some time this summer tracking down the correct versions of the gems we use and I suspect there are some that can even be discarded entirely in favor of features that are now built into Rails (or simple enough to reimplement internally, depending on how much of the gems functionality we really need). I'll be extrapolating from this guide. The scariest part is the lack of tests. My plan is to write some rough integration tests for the user-facing functionality and use those as guideposts.

Adding tests sounds like a good project. Upgrading the stack when the real devs are on vacation sounds like a bad project. Do you not have a backlog of tickets to pull from?


Maista posted:

code:
    ActiveRecord::Base.connection.execute <<-SQL
      CREATE MATERIALIZED VIEW mw_permits NEVER REFRESH AS
        SELECT mw_journals.*
        FROM mw_journals
        INNER JOIN mw_case ON mw_case.ID = m_journal.CASE_ID
        WHERE 1=1
        #{"AND (#{case_config_selection})" if case_config_selection.present?}
    SQL
The thing that bothers me about this code is that it seems to break the abstraction layer that ActiveRecord provides and that it uses Oracle-specific syntax which leads to vendor lock-in, both of which I've been told are bad things by both my teachers and my textbooks.

Is there a better way to solve this? My first thought was simply to pump data into temporary tables and replacing the old table once the pump job completes. This should ensure that the database is always in a consistent state for the app, right?

I would be interested in the context for this. But there's nothing wrong with including database-specific raw SQL, every codebase has that

Adbot
ADBOT LOVES YOU

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Rake tasks shouldn't be sharing variables like that. Offload the "populates and returns a hash" parts to a `lib/my_library.rb` class

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Is anyone good at Sidekiq here? I have a deferred job on it's own queue, and I want to limit the total enqueued job for that queue to 1 at a time.

some pseudocode here is what I'm trying to achieve, just not sure how to do this with the Sidekiq API:
Ruby code:
def deferred_thing(some_param: some_param)
  if ::Sidekiq::Queue.find("my_specific_queue_name").enqueued_count == 0 # this is not real	
    ::MyJobs::MySpecificQueueJob.perform_later(some_param)
  end
end
Yes, I've read the Sidekiq docs

edit: not thoroughly though. found one solution using the 'Stats' module like this:
Ruby code:
Sidekiq::Stats.new.queues['my_specific_queue_name']

A MIRACLE fucked around with this message at 22:07 on Sep 15, 2017

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Just wanted to post here and thank ya'll for the help over the past uhh 7 years? or so. The initial enthusiasm here for the platform inspired me to learn web development and is the primary reason I have such a kick rear end career now. Cheers yall

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Doh004 posted:

Someone just got a promotion.

I'm the lead/sole backend dev at a startup in LA and have been for a while, we hit first bookable revenue this month which is a nice milestone.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Sub Par, I think I know what you're asking. you're going to want to read up on ActiveJob class inheritors and use something like Sidekiq to manage async processes

Then in your controller you're going to want something like

controllers/my_active_record_thing_controller.rb
Ruby code:
# controller 
# POST
def create
  ::MyActiveRecordThing.create(create_params)

  head :created
end

# GET
def show
  @thing = ::MyActiveRecordThing.find(params[:id])
end
Then use the model as a dummy controller inside the after_create hook to call your job
models/my_active_record_thing.rb
Ruby code:
after_create :async_after_create_tasks

def async_after_create_tasks
  ::MyActiveRecordThing::AfterCreateJob.perform_later(id: self.id)
end

def after_create_tasks
  self.external_api_stuff = get_api_stuff
  self.munge!
  self.save
end
then in jobs/my_active_record_thing/after_create_job.rb
Ruby code:
class MyActiveRecordThing::AfterCreateJob < ActiveJob::Base
  def perform(id:)
    ::MyActiveRecordThing.find(id).after_create_tasks
  end
end
any yeah, you're going to have to use a bit of javascript to long poll/ping the show endpoint to know when the calculation is there. or do something fancy with sockets idk

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

pretty much any controller endpoint that calls an external API for the user should be async. As a rule I only do the minimum work necessary for a valid response in the endpoint, and offload everything else to worker jobs. I've allowed my app developers a `&sync=true` param for a couple endpoints if they want to wait for the data on demand, like a credit check on the current user for example. This might be bad design but I have to make concessions to the front end guys occasionally because a positive work relationship with them is a lot more important to me than adhering absolutely to REST design principles. I'm also the sole API / browser developer at my startup so I get to make these decisions and deal with the fallout (or lack thereof) down the line. So far it's been fine

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Well my startup went belly up. If anyone wants to hire me for remote or local to LA pm me. I got a decent CV and some lead / senior level experience

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Post your raw sql that’s working and I’ll try to come up with a better query

Also you don’t have to do everything with ActiveRecord aliases, sometimes it’s easier and makes sense to use raw sql

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

just wanna reiterate that you should be mocking pretty much everything except the bits of domain logic the unit test is specifically for. this will make your poo poo way faster

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Just switch to serverless everyone’s doing it

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

how are the models related?

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

is anyone here good at searchkick

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Peristalsis posted:

I've moved a couple of partials to be rendered asynchronously with the render_async gem. They were slow loading tabs on a show page, and moving them broke tests, because (I think) the tests don't know to wait for the asynchronous tabs to finish loading. I'd like a way to continue testing these tabs. I found that RSpec/capybara is supposed to be able to render partials, but when I try that in feature tests, render is not a recognized method name. This app doesn't have dedicated controller tests, which is where I assume this is actually supposed to go, and I don't know if those allow standard UI expectations anyway. Does anyone have any suggestions for a good way to test this?

post your test? is it a controller type test?

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

This is the kind of thing I would hop on a screen share call for. But it’s basically you’re at the point that you need to learn the chrome or Firefox debuggers and how to set breakpoints in your front end

Dm me tomorrow if you’re still having issues I can try to help

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

what would it take to become a rails "expert" do y'all think. my manager wants me to become an "expert" in rails this year but I don't think he really understands what that means either, or is able to quantify it. So I have to invent some kind of metric around this to put on my evaluation for next year basically lol. I already know rails pretty dang good

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

to be fair migrating 2 to 3 is a huge pain in the rear end

heroku is the opposite of a pain in the rear end

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

is docker sync still a thing

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

I would love some more info on that... Still using docker sync on an old project and it sucks. I have to restart it constantly because it won't pick up big version changes like files being removed etc. Or it just, forgets that it's supposed to be running sometimes and I'll be racking my brain trying to figure out why the build is wonky. Big rails 4 codebase via docker-compose on a Mac

edit, maybe using the nfsmount volume..? I'm gonna try some stuff today

A MIRACLE fucked around with this message at 19:43 on Jul 28, 2021

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Hey y'all. I'm working on a rails app for the first time in a while, trying to remember how eager loading works while writing a map / serializer json thingy and hitting mad N+1 queries on it

here's a really contrived example of what I'm trying to do

Ruby code:
class Person < ApplicationRecord
  has_many :person_organizations, dependent: :restrict_with_error

  has_many :organizations, through: :person_organizations

  scope :with_details, (lambda do
    includes(person_organizations: [:organization])
  end)
end
Ruby code:
Person.with_details.map { |p| puts p.organizations.map(&:external_reference_id) } # n+1 query  :(
please help me

edit... it seems like doing eager loading inside a scope doesn't work. invoking includes it outside a named scope works fine

edit, I'm actually just doing it wrong

A MIRACLE fucked around with this message at 23:26 on Apr 20, 2022

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

post the error youre getting

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

I have a service that is returning multiple headers with the same name and Faraday only adds one header to the response_headers per name. So it's keeping the first header and dropped the rest of them. guess I can try this in Net::HTTP

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

I’m open to suggestions. I dug pretty deep into the gem with my debugger and can’t figure out a good place to monkey patch it. Or if I am doing it wrong. Was hoping to get it working in faraday cause I already built a whole library around it

A MIRACLE fucked around with this message at 00:34 on Jun 1, 2023

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

I’m still doing rails and making good money at it. Node is good to know too, you can even cross over to .net if you want

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

turbo is cool. I haven't gotten to the "stimulus" part of "hotwire" yet. is all this really better than doing a create-react-app ?

Pardot posted:

Is it merging them down to a single one with commas? https://github.com/lostisland/faraday/issues/1120

sorry didn't reply before but I was having trouble getting at any value in the list after the first one. and I would have been happy to split it myself but I couldn't find a way to get at a raw header value either.. I haven't had to page through okta api user lists since then but I am going to have get it working on the library sooner than later lol.

might have to use the standard http lib for that request. but theres a company policy (a policy I made up) to not use other http libraries than faraday lmao. standard lib doesn't count

A MIRACLE fucked around with this message at 06:23 on Nov 19, 2023

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Applied to a job at <popular rails hosting company> and got a form response rejection. Not even an HR screen? Maybe I’m slipping..

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

faraday is driving me up the wall today. it was decoding and re encoding my URL params in ways that are incompatible with the API i'm calling, so I thought, ok I will try writing a custom param encoder. which it is hitting but then not respecting at all. like why does it do this

Ruby code:
    class ParamsEncoder
      class << self
        def encode(params)
          encoded_params = []

          params.each do |k, v|
            encoded_param = ERB::Util.u(v)

            encoded_params << "#{k}=#{encoded_param}"
          end

          encoded_params.join('&') # at this point the params look good -> eg search=login%20eq%20%22myemail%40gmail.com%22
        end
then it makes the request with this URL instead??

code:
  HTTP GET (92.50ms)   REDACTED/api/v1/users?search=login eq "myemail@gmail.com"
edit, bleh of course as soon as I post this I realise its just the logger trying to make things more readable and the real issue is I'm using the api slightly wrong

A MIRACLE fucked around with this message at 18:53 on Feb 20, 2024

Adbot
ADBOT LOVES YOU

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

A MIRACLE posted:

Applied to a job at <popular rails hosting company> and got a form response rejection. Not even an HR screen? Maybe I’m slipping..

lol just wanted to update, i guess a real person finally read my stupid markdown resume and was like when can we talk??

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