jjb / ruby-clock

A ruby job scheduler which runs jobs each in their own thread in a persistent process.
MIT License
78 stars 1 forks source link

Long running tasks are blocking others from running? #45

Closed johnnncodes closed 3 months ago

johnnncodes commented 3 months ago

hello:japan should run every second but it looks like it's being blocked to run every second by hello:world

Clockfile:

using RubyClock::DSL

every('5 seconds') do
  rake('hello:world')
end

every('1 second') do
  rake('hello:japan')
end

hello.rake:

namespace :hello do
  task :world => :environment do
    Rails.logger.info "hello world #{Time.now}"

    sleep(10)
  end

  task :japan => :environment do
    Rails.logger.info "hello japan #{Time.now}"
  end
end

Logs:

hello japan 2024-07-22 03:48:40 +0000
hello japan 2024-07-22 03:48:42 +0000
hello japan 2024-07-22 03:48:43 +0000
hello japan 2024-07-22 03:48:43 +0000
hello world 2024-07-22 03:48:45 +0000
hello japan 2024-07-22 03:48:55 +0000
hello japan 2024-07-22 03:48:55 +0000
hello japan 2024-07-22 03:48:55 +0000
hello japan 2024-07-22 03:48:55 +0000
hello japan 2024-07-22 03:48:55 +0000
hello world 2024-07-22 03:48:55 +0000
hello japan 2024-07-22 03:49:05 +0000
hello japan 2024-07-22 03:49:05 +0000
hello japan 2024-07-22 03:49:05 +0000
hello japan 2024-07-22 03:49:05 +0000
hello japan 2024-07-22 03:49:05 +0000
hello world 2024-07-22 03:49:05 +0000
johnnncodes commented 3 months ago

Closing. I just figured out that rake is blocking and I can use rake_async:

https://github.com/jjb/ruby-clock/blob/main/lib/ruby-clock/rake.rb#L24