Activity Graph

Page 1 of 1


[07:59:48] old_relik: has joined #ruby
[08:00:40] old_relik: I have a list of maps like this: [{"id"=>"3e8f493a-5662-4f10-9ac7-04fff7988009", "data"=>87}]
[08:01:49] old_relik: how can I easily turn this into {"3e8f493a-5662-4f10-9ac7-04fff7988009" => {"data" => 87}, "2312f493a-5662-4f10-1831-04fff7988009" => {"data" => 81}}
[08:22:00] old_relik: had no idea you could to a block with to_h
[08:57:29] old_relik: Quit: Page closed


[09:37:48] old_relik: has joined #RubyOnRails
[09:38:23] old_relik: doing a thing like: 1. db write 2. api call 3. db write
[09:38:30] old_relik: can I make this transaction in anyway
[09:38:41] old_relik: i.e. if the api call throws an exception the db writes rollback
[09:38:53] old_relik: transactional*
[11:35:39] old_relik: Ping timeout: 256 seconds


[06:45:09] old_relik: has joined #RubyOnRails
[06:45:20] old_relik: i want to create a bot user during the startup of my app
[06:45:25] old_relik: what is the right place for doing such a thing?
[08:00:19] old_relik: Ping timeout: 256 seconds


[03:43:57] old_relik: has joined #ruby
[03:44:47] old_relik: Client Quit
[04:54:05] old_relik: has joined #RubyOnRails
[04:54:22] old_relik: I have some simple date time comparison utility method
[04:54:29] old_relik: where should it go?
[04:54:42] old_relik: it's used in service objects and sidekiq jobs
[05:53:01] old_relik: Quit: Page closed


[17:35:00] old_relik: has joined #RubyOnRails
[17:35:57] old_relik: how does the sidekiq logs show up on the rails process logs?
[17:44:39] old_relik: Quit: Page closed


[09:43:19] old_relik: has joined #RubyOnRails
[09:43:42] old_relik: how do I group records by it's parent id in a single query?
[09:44:10] old_relik: Model.group(:parent_id) doesn't work
[09:44:51] old_relik: I want something like: {"c25c67c7-f7f1-43a0-88d0-059f5c591e64" => [children objects], "001b09bb-daf5-48fa-8f3f-5f423ce9e319" => [children objects]}
[09:45:00] old_relik: without using group_by
[09:47:52] old_relik: Client Quit


[18:40:16] old_relik: has joined #RubyOnRails
[18:40:19] old_relik: how can I get the time object for time at a specifc time of the day
[18:40:20] old_relik: like 2pm for today
[18:41:50] old_relik: and also give next day if its already past 2pm
[18:42:51] old_relik: has joined #ruby
[18:43:45] old_relik: x-post from #rubyonrails: is there an easy way to get time object for time at a specifc time of the day, like 2pm for today, but give 2pm for next day if it's already past 2pm today
[19:04:36] old_relik: Quit: Page closed


[17:34:37] old_relik: has joined #ruby
[17:35:38] old_relik: I have a job (activejob / sidekiq) that gets a bunch of IDs to process and for each, send an sms and then log it into a database
[17:37:03] old_relik: if this processing of an ID throws an exception, I don't want it to retry the job because the other IDs in the batch would get reprocessed again
[17:37:30] old_relik: I can solve this in two ways afaict:
[17:37:39] old_relik: 1. disable retries for the job
[17:38:01] old_relik: 2. rescue exceptions in the processing and just 'next'
[17:38:13] old_relik: does that seem sensible?
[17:38:57] old_relik: yeah, I was trying to make it idempotent
[17:39:30] old_relik: but it's a bit tricky because the idempotency is a bit domain specific
[17:39:38] old_relik: but the job is a bit generic
[17:44:04] old_relik: mikecmpbll: right
[17:45:22] old_relik: ok, let me try
[17:48:05] old_relik: mikecmpbll: https://dpaste.de/9sej
[17:49:09] old_relik: mikecmpbll: I can wrap this around an if as you said and ensure its idempotent
[17:49:43] old_relik: the issue is that the idempotency condition is specific to the "comunication_type"
[17:49:58] old_relik: and I don't want that condition to sit here
[17:50:11] old_relik: that condition is already applied before the job is spun
[17:50:28] old_relik: but of course, that doesn't guarantee against retries
[18:09:41] old_relik: adam12: I considered this
[18:10:02] old_relik: but wouldn't I run into the same problem?
[18:11:01] old_relik: oh right, so like AbstractEntryPointJob --> SpinUpDomainSpecificIdempotentJobs?
[18:13:25] old_relik: adam12: right, thanks, but I think that won't work for me
[18:13:38] old_relik: I actually need the job to process a bunch of messages, because there are a lot
[18:13:49] old_relik: don't want to spawn 100k jobs
[18:15:13] old_relik: each job is a fixed size of data
[18:16:20] old_relik: I don't want it to retry (but that's only because it's not idempotent)
[18:17:09] old_relik: I can handle that simply by rescuing and moving on
[18:18:23] old_relik: my question i guess is a design question
[18:18:27] old_relik: I can solve this problem
[18:19:34] old_relik: I would _prefer_ if the job were idempotent
[18:19:43] old_relik: even if it doesn't need it to be
[18:19:47] old_relik: i don't know if that makes sense
[18:19:53] old_relik: adam12: why would you say so?
[18:19:56] old_relik: mikecmpbll: right
[18:20:37] old_relik: you're completely right
[18:22:29] old_relik: mikecmpbll: an easy way to make this idempotent would be something like this: https://dpaste.de/5gYP
[18:22:56] old_relik: my worry is the modeling here, that condition leaks what is effectively a highly specific condition to the Model
[18:23:11] old_relik: but job tries to be generic
[18:27:39] old_relik: mikecmpbll: thanks for trying to help, but I realize how hard it is to explain these things on IRC
[18:28:21] old_relik: mikecmpbll: basically, I guess the job is for sending any "kind" of SMS. the Model understands many kinds of SMSes
[18:28:39] old_relik: and each kind has it's unique idempotency condition
[18:28:50] old_relik: and so either the job needs to become type specific
[18:28:56] old_relik: or any of the other things we spoke above
[18:29:28] old_relik: i'm torn between the two
[18:29:51] old_relik: maybe that's something that I should explore
[18:29:55] old_relik: hide the details
[18:31:46] old_relik: thanks a lot
[18:31:46] old_relik: this was helpful
[19:14:30] old_relik: Quit: Page closed


[12:53:23] old_relik: has joined #RubyOnRails
[12:53:55] old_relik: can i initialize a model in initializers?
[12:54:03] old_relik: I want to create record during app boot
[12:54:17] old_relik: but models are inaccessible from lib/initializers.rb
[12:54:27] old_relik: or rather haven't loaded yet
[14:13:35] old_relik: Ping timeout: 256 seconds


[11:34:11] old_relik: has joined #ruby
[11:35:10] old_relik: is there a better way of writing this fn https://dpaste.de/iref
[11:39:45] old_relik: Ping timeout: 256 seconds


[15:05:16] old_relik: has joined #ruby
[15:07:10] old_relik: what do people think of code like this https://dpaste.de/8YF3
[15:07:53] old_relik: this service is called via a sidekiq job, and to avoid creating multiple jobs for multiple types, I dispatch methods on types
[15:08:02] old_relik: but then it feels a bit icky for some reason
[15:12:21] old_relik: Ping timeout: 256 seconds


[17:35:52] old_relik: has joined #ruby
[17:36:24] old_relik: rspec question: how do I test the side-effect caused in a rescue block that re-raises a different exception
[17:39:02] old_relik: https://dpaste.de/kUN5
[17:39:50] old_relik: the report_error function makes another 3rd party call that I would like to mock out
[17:40:48] old_relik: phaul: so one could just do https://dpaste.de/Ea7M
[17:41:09] old_relik: but then I don't know how to test whether the work in report_error was done as well
[17:42:02] old_relik: the work isn't a simple database change, if that were the case I could've done a compound assertion with "change"
[17:42:26] old_relik: the work requires me mocking Raven (a sentry client)
[17:42:49] old_relik: so something like this: "expect(Raven).to receive(:capture_message).and_return(true)"
[18:10:42] old_relik: phaul: thanks
[18:10:45] old_relik: that's what I had tried
[18:10:52] old_relik: but I think I'm doing something wrong in my code
[18:10:56] old_relik: the expect isn't working
[18:54:21] old_relik: Quit: Page closed


[06:24:15] old_relik: has joined #RubyOnRails
[06:24:46] old_relik: how does one deal with 0 records with kaminari generically? when you do .per(0) it blows up
[06:37:11] old_relik: Quit: Page closed


[11:15:03] old_relik: has joined #RubyOnRails
[11:15:25] old_relik: i have a model method that calls another method that makes a db query multiple times
[11:15:31] old_relik: in the same function
[11:15:37] old_relik: and then it ends up making multiple queries
[11:16:46] old_relik: other than saving it on top of the method call
[11:17:09] old_relik: is there a cleaner way to do this, such that I can simply call the method and it will only make the query once
[12:15:04] old_relik: Quit: Page closed


[12:32:42] old_relik: has joined #RubyOnRails
[12:33:37] old_relik: is there a way for the a relationship to access the caller assocation? So I have a Prison that has many criminals and if I do "Criminal.first.prison"
[12:34:05] old_relik: Can I somehow acquire the Criminal back from the context of prison?
[12:34:12] old_relik: Like "Criminal.first.prison.criminal"
[13:37:51] old_relik: Quit: Page closed


[07:25:13] old_relik: has joined #RubyOnRails
[07:25:30] old_relik: is it recommended to memoize within activerecord models?
[07:25:47] old_relik: memoize expensive query results
[07:26:06] old_relik: like mapping over a function that makes a query
[08:17:24] old_relik: Quit: Page closed
[17:12:31] old_relik: has joined #RubyOnRails
[17:17:50] old_relik: is there a way to do rails association if the association is not on either id col, for eg, Model A has_many Model B. Model B knows about A with a custom col call a_uuid and uses a custom column on A call real_a_id
[17:27:39] old_relik: Quit: Page closed
[17:56:46] old_relik: has joined #RubyOnRails
[17:57:46] old_relik: I actually got it to work: has_many model_b -> (model_a) { where(a_uuid: model_a.real_a_id) }, foriegn_key: 'a_uuid'
[17:58:19] old_relik: but it puts a random model_b.a_uuid IS NULL in my query
[17:58:34] old_relik: I have no idea why
[17:59:03] old_relik: when I do ModelA.first.model_bs
[18:23:00] old_relik: has joined #ruby
[18:38:19] old_relik: Quit: Page closed


[16:30:14] old_relik: has joined #ruby
[16:35:52] old_relik: Quit: Page closed


[17:59:16] old_relik: has joined #RubyOnRails
[17:59:59] old_relik: I'm trying to write a rails (ar) query for this https://dpaste.de/mBjc
[18:00:14] old_relik: finding it very hard to do it idiomatically, could someone help?
[18:11:30] old_relik: I currently have this: https://dpaste.de/UMJF
[18:11:47] old_relik: but the join query is not building correctly
[18:46:34] old_relik: Quit: Page closed


[13:13:09] old_relik: has joined #ruby
[13:14:02] old_relik: Is it idiomatic to memoize constants like this: APP_HOST ||= ENV.fetch('APP_HOST')
[13:17:52] old_relik: so it's technically a rails "concern"
[13:18:01] old_relik: and is under the "included" block
[13:18:13] old_relik: and hence gets loaded a few times (esp during tests)
[13:19:09] old_relik: and hence throws the re-assign warning
[13:20:03] old_relik: what would you recommend?
[13:22:38] old_relik: oh like a self accessor
[13:22:53] old_relik: however this must sit in a module (rails concern)
[13:33:29] old_relik: so I just moved the constants from "included do" to out in the normal module scope
[13:33:33] old_relik: and it works
[13:33:44] old_relik: they are accessible in the included block
[13:34:30] old_relik: I'm not entirely sure why that worked though
[13:36:04] old_relik: phaul: https://dpaste.de/vbKe
[13:36:18] old_relik: so that works
[13:36:51] old_relik: what I previously had was this: https://dpaste.de/eY7z
[13:36:55] old_relik: (which was throwing warnings)
[13:37:07] old_relik: [apologies if this is rails domain]
[13:37:37] old_relik: yeah, I might have not made that clear
[13:37:59] old_relik: it's completely ok for it to be init'd once
[13:40:51] old_relik: Quit: Page closed


[13:57:14] old_relik: has joined #ruby
[14:02:36] old_relik: Is there a method in ruby that can split a string into all possible ways? like "1234" will become [["1", "234"], ["12", "34"], ["123", "4"], ["1", "23", "4"], ["1", "2", "34"], ["12", "3", "4"], ["1", "2", "3", "4"]]
[14:10:36] old_relik: want to keep the order
[14:10:59] old_relik: and also ensure that the split sets union up to the original array
[14:11:25] old_relik: kinda like https://en.wikipedia.org/wiki/Bell_number#Set_partitions
[14:11:31] old_relik: but maintaining the order as well
[14:12:31] old_relik: I was actually just trying to solve http://rubyquiz.com/quiz20.html
[14:40:37] old_relik: Quit: Page closed


[09:31:17] old_relik: has joined #RubyOnRails
[09:31:56] old_relik: User.transaction { self.save!; HTTPCall.execute() } –– is something like this safe to do if I want to prevent the HTTPCall from going through if the transaction throws an exception?
[09:33:02] old_relik: And would it also be foolproof against COMMIT failures?
[10:09:54] old_relik: Quit: Page closed


[08:06:23] old_relik: has joined #ruby
[08:08:33] old_relik: can this be written this more succintly? https://pastebin.com/raw/Xue252eN
[08:10:18] old_relik: sorry made a mistake, the body is actually not identical
[08:26:23] old_relik: Quit: Page closed


[04:36:52] old_relik: has joined #ruby
[04:37:17] old_relik: what is the purpose of having "25px".to_i return 25? isn't that confusing?
[04:40:26] old_relik: I get that, but isn't the other way around broken
[04:40:50] old_relik: why wouldn't I ever want the conversion to be strict
[04:43:05] old_relik: I did, and I know it mentions that it ignores characters past the end of a valid number
[04:43:12] old_relik: it just seems unintuitive
[04:43:35] old_relik: and a use-case that shouldn't be a standard library especially something calles String#to_i
[04:50:27] old_relik: Ping timeout: 252 seconds