crono with rake tast only execute one time on start #38

Closed
opened 2025-12-29 00:21:41 +01:00 by adam · 2 comments
Owner

Originally created by @sun1752709589 on GitHub (Jan 22, 2017).

Rails 5.0.1
ruby 2.3.3

here is my code:
namespace :crono do
  desc "hello"
  task :hello => :environment do
    puts 'hello...'
  end
end

in cronotab.rb:
require 'rake'

Rails.app_class.load_tasks

class Test
  def perform
    Rake::Task['crono:hello'].invoke
  end
end
Crono.perform(Test).every 5.seconds
Originally created by @sun1752709589 on GitHub (Jan 22, 2017). Rails 5.0.1 ruby 2.3.3 ``` here is my code: namespace :crono do desc "hello" task :hello => :environment do puts 'hello...' end end in cronotab.rb: require 'rake' Rails.app_class.load_tasks class Test def perform Rake::Task['crono:hello'].invoke end end Crono.perform(Test).every 5.seconds ```
adam closed this issue 2025-12-29 00:21:42 +01:00
Author
Owner

@bethadele commented on GitHub (Feb 15, 2017):

Once the rake task is invoked in this context, Rails will prevent it from running again unless you specifically re-enable it.

class Test
  def perform
    Rake::Task['crono:hello'].reenable
    Rake::Task['crono:hello'].invoke
  end
end

See this blog post for a little more detail.

@bethadele commented on GitHub (Feb 15, 2017): Once the rake task is invoked in this context, Rails will prevent it from running again unless you specifically re-enable it. ``` class Test def perform Rake::Task['crono:hello'].reenable Rake::Task['crono:hello'].invoke end end ``` See [this blog post](https://til.hashrocket.com/posts/4897ed42b7-invoking-rake-tasks-multiple-times) for a little more detail.
Author
Owner

@sun1752709589 commented on GitHub (Feb 16, 2017):

@bethadele Thank you

@sun1752709589 commented on GitHub (Feb 16, 2017): @bethadele Thank you
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/crono#38