Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to start periodically task inside falcon? #162

Open
sergio-fry opened this issue Dec 9, 2021 · 4 comments
Open

How to start periodically task inside falcon? #162

sergio-fry opened this issue Dec 9, 2021 · 4 comments
Assignees

Comments

@sergio-fry
Copy link

sergio-fry commented Dec 9, 2021

I am going to build all-in-one application: web, RMQ consumer, periodically tasks, etc. I can't understand how to do it with falcon. I can't access Asyc::Task.current directly, because it is not initialized inside config.ru. Could you explain how can I do that?

@webgago
Copy link

webgago commented Oct 9, 2022

@sergio-fry I guess this is no longer relevant but let me just leave it here.

https://github.com/socketry/timers

require 'timers'

timers = Timers::Group.new

five_second_timer = timers.after(5) { puts "Take five" }
every_five_seconds = timers.every(5) { puts "Another 5 seconds" }

loop { timers.wait }

@ioquatix
Copy link
Member

We can probably change this so that the config.ru is constructed within the top level async block... let me check.

@sergio-fry
Copy link
Author

@webgago thanks!

@ioquatix ioquatix self-assigned this Oct 25, 2022
@ioquatix ioquatix reopened this Oct 25, 2022
@projecteurlumiere
Copy link

projecteurlumiere commented May 20, 2024

@ioquatix some time has passed since the original question was asked, but still...

Is there a way to spawn an async task that operates concurrently in relation to Falcon's spawned request-related tasks? The code below seemingly achieves the goal but is it possible to do that with async only?

def subscribe
  Thread.new do
    @redis.subscribe("app_#{APP_ID}") do |on|
      on.message do |channel, message|
        LOGGER.debug "message on channel #{channel}: #{message}"
        MUTEX.synchronize { SubService.new(channel, deserialize(message)) }
      end
    end
  end
end

The thread in the code above is instantiated when the application starts and keeps waiting for sub messages. When a message is received, the thread intervenes between whatever Falcon is doing. Is it possible to get this behavior without threads? Perhaps, by adding this as a task to Falcon's main event-loop? How can I achieve that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants