Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8656425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:16:20+00:00 2026-06-12T15:16:20+00:00

Thor like Rake (and Make) has task management. If I call a task multiple

  • 0

Thor like Rake (and Make) has task management. If I call a task multiple times, it will effectively call the task only once. How can I call a task multiple times?

I tried modifying the @_invocations hash, but that did not work:

require 'csv'
require './config/environment'

class MisReport < Thor

  desc "all", "generate mysql and postgres mis"
  def all
    generate("pg_mis_report", "pg")
    generate("mysql_mis_report", "mysql") 
  end

  desc "generate", "generate mis report"
  def generate(file_name = "mis_report_#{Time.now.to_s(:number)}", connection = "postgres") 
    if connection == "pg"
      puts "== postgres database"
      ActiveRecord::Base.establish_connection :development_mysql
    else
      puts "== mysql database"
      ActiveRecord::Base.establish_connection :development
    end

    # generate MIS

    puts
    puts "mis file is at: #{file_path}"
  end

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:16:21+00:00Added an answer on June 12, 2026 at 3:16 pm

    Looking through the Thor docs I couldn’t find a way to force invokation of the same task multiple times. This is probably by design.

    I’ve created a workaround that will do what you ask by combining the report generation requests into a single task which in turn relies on a the “no_task” block Thor makes available for non-task methods. You have the flexibility to add new reports to be generated by adding them to the hash argument passed to generate.

    class MisReport < Thor
    
      desc "all", "generate mysql and postgres mis"
      def all
        generate({:pg_mis_report => "pg", :mysql_mis_report => "mysql"})
      end
    
      desc "generate", "generate mis report"
      def generate(hash)
        hash.each_pair {|file_name, connection| generate_report(file_name.to_s, connection)}
      end
    
      no_tasks{
        def generate_report(file_name = "mis_report_#{Time.now.to_s(:number)}", connection = "postgres") 
    
          if connection == "pg"
            puts "== postgres database"
            #ActiveRecord::Base.establish_connection :development_mysql
          else
            puts "== mysql database"
            #ActiveRecord::Base.establish_connection :development
          end
    
          # generate MIS
    
          file_path = "/some/path/to/#{file_name}"
          puts
          puts "mis file is at: #{file_path}"
        end
      }
    
    end
    

    I’ve tested it and output is shown here:

    $> thor mis_report:all
    == postgres database
    
    mis file is at: /some/path/to/pg_mis_report
    == mysql database
    
    mis file is at: /some/path/to/mysql_mis_report
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to call a thor task from a Migration. With rake I can
I would like to use the popular Thor gem to create a daemonized task.
Is it possible to call a specific task first, when i run a thor
I'm writing a library that has an embedded Sinatra app launched via Thor. I
I'm trying to figure out how the Thor gem creates a DSL like this
When using thor I am used to writing code like this, desc import, Import
I've just started using Thor. I've been looking around the documentation and can't find
This is Thor task: desc 'readkeys', 'Read keys' method_option :password, :type => :string, :desc
I'm looking for a way to create a command-line thor app that will run
I'm building a simple thor based generator for some internal projects, and can't seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.