Questions tagged [concurrent-ruby]

Concurrency library inspired by Erlang, Clojure, Scala, Haskell, F#, C#, Java, and others. Use this tag for questions related to the concurrent-ruby gem.

Concurrent Ruby is a concurrency library for Ruby inspired by Erlang, Clojure, Scala, Haskell, F#, C#, Java, and others, providing abstractions for agents, futures, promises, thread pools, supervisors, and more.

Documentation, source code, and other information at http://www.concurrent-ruby.com/.

21 questions
19
votes
3 answers

Multithreading in Rails: Circular dependency detected while autoloading constant

I have a Rails app in which I have a Rake task that uses multithreading functions supplied by the concurrent-ruby gem. From time to time I encounter Circular dependency detected while autoloading constant errors. After Googling for a bit I found…
edwardmp
  • 6,339
  • 5
  • 50
  • 77
12
votes
3 answers

Handle exceptions in concurrent-ruby thread pool

How to handle exceptions in concurrent-ruby thread pools (http://ruby-concurrency.github.io/concurrent-ruby/file.thread_pools.html)? Example: pool = Concurrent::FixedThreadPool.new(5) pool.post do raise 'something goes wrong' end # how to…
user5391923
9
votes
1 answer

How do I wait for multiple asynchronous operations to finish before sending a response in Ruby on Rails?

In some web dev I do, I have multiple operations beginning, like GET requests to external APIs, and I want them to both start at the same time because one doesn't rely on the result of the other. I want things to be able to run in the background. I…
Matt Welke
  • 1,441
  • 1
  • 15
  • 40
4
votes
1 answer

Chain an array of tasks in Concurrent Ruby

I have a set of tasks that I want to execute sequentially in some background thread, with the result of each task being passed to the next, and with the chain failing if any link in the chain fails. For the sake of argument, let's say each task is…
David Moles
  • 48,006
  • 27
  • 136
  • 235
3
votes
0 answers

How to remove a future job with sucker_punch

I'm using sucker punch future job but sometimes I need to remove it in another request before it is executed. For that I have to find it by the args I passed to the job before being able to kill it.
AlexLarra
  • 841
  • 5
  • 18
3
votes
2 answers

How do I catch an error from a thread and then re-throw that error when all the threads have completed?

I'm using Rails 5. I have this gem for managing threads ... gem 'concurrent-ruby' I notice that if one of my threads throws an error, it is just swallowed and I never find out about it. I tried this in a console pool =…
user7055375
2
votes
2 answers

How ought I limit Thread creation using Concurrent-Ruby?

I have a process which uses the concurrent-ruby gem to handle a large number of API calls concurrently using Concurrent::Future.execute, and, after some time, it dies: ERROR -- : can't create Thread (11)…
Dave Sag
  • 13,266
  • 14
  • 86
  • 134
1
vote
0 answers

concurrent-ruby slow in making db calls with Rails 5

I have been using concurrent-ruby 1.1.5 with Rails 5.1.6 and MySQL 8.0. I have to make 500 DB calls, so I tried to make it using concurrent ruby but the results are extremely slow than expected Normal Loop call - This takes on an average 7-8…
1
vote
2 answers

Ruby on Rails - Best way to asynchronously make long api calls and return values to js on the frontend?

I am creating a search page that displays up to 9 rates. On the frontend, I am sending a request to my rails application that contains the necessary data to grab the 9 rates. In one of my rails controllers, I crawl a webpage to get the rate. This…
windfallisland
  • 79
  • 1
  • 11
1
vote
1 answer

override activerecord callbacks to run them asynchronously

i am working on a rails app and currently we are migrating to jruby. we currently have over 10 after callbacks on the one of our models and this is blocking the response for a long time. after_update :sync after_update :send after_create…
fady zohdy
  • 45
  • 1
  • 8
0
votes
0 answers

trying to make call in thread pool but get "curl: (23) Failed writing body"

I am trying to make a bunch of web calls in the background, and am basically doing: class AmazingMultiThreadedWebCallMachine module Worker extend self def perform_task(row) response = `curl -H "Content-type:…
patrick
  • 9,290
  • 13
  • 61
  • 112
0
votes
1 answer

Concurrent Ruby- Thread Pool vs Promises

I currently have some code where I retrieve data from a bunch of URLs. At the moment, I'm doing this sequentially. In order to speed it up, I want to do this concurrently. To implement this, I'm using the concurrent-ruby gem. Since I have a lot of…
0
votes
2 answers

Concurrent-ruby async method calling problem

Ruby version: ruby-3.2.1 I have a requirement of reading a csv file which contains 50k rows. Then with each row i need to execute 7 APIs one by one in the order to create an entry in a third part application. I am trying to use async feature of…
Ajith
  • 325
  • 4
  • 17
0
votes
1 answer

How to wait for all Concurrent::Promise in an array to finish/resolve

@some_instance_var = Concurrent::Hash.new (0...some.length).each do |idx| fetch_requests[idx] = Concurrent::Promise.execute do response = HTTP.get(EXTDATA_URL) if response.status.success? ... # update @some_instance_var end …
Bmr
  • 23
  • 4
0
votes
1 answer

Can you mutate value of Concurrent::ThreadLocalVar?

I'm using Concurrent::ThreadLocalVar from concurrent-ruby. Is it okay to mutate the value like this: numbers = Concurrent::ThreadLocalVar.new([]) numbers.value # => [] numbers.value.append(1) numbers.value # => [1] Or should I reassign the value?…
Kris
  • 19,188
  • 9
  • 91
  • 111
1
2