<commit_before>module Luban
  module Deployment
    class Command < Luban::CLI::Command
      module Tasks
        module Install
          Actions = %i(setup build destroy cleanup binstubs
                       show_current show_summary which whence)
          Actions.each do |action|
            define_method(action) do |args:, opts:|
              raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
            end
          end

          def installable?; true; end

          protected

          def setup_install_tasks
            _self = self
            task :setup do
              desc "Setup #{_self.display_name} environment"
              action! :setup
            end

            task :build do
              desc "Build #{_self.display_name} environment"
              switch :force, "Force to build", short: :f
              action! :build
            end

            task :destroy do
              desc "Destroy #{_self.display_name} environment"
              switch :force, "Force to destroy", short: :f, required: true
              action! :destroy
            end

            task :cleanup do
              desc "Clean up temporary files during installation"
              action! :cleanup
            end

            task :binstubs do
              desc "Update binstubs for required packages"
              switch :force, "Force to update binstubs", short: :f
              action! :binstubs
            end

            task :version do
              desc "Show current version for app/required packages"
              action! :show_current
            end

            task :versions do
              desc "Show app/package installation summary"
              action! :show_summary
            end

            task :which do
              desc "Show the real path for the given executable"
              argument :executable, "Executable to which"
              action! :which
            end

            task :whence do
              desc "List packages with the given executable"
              argument :executable, "Executable to whence"
              action! :whence
            end
          end
        end

        module Deploy
          Actions = %i(deploy)
          Actions.each do |action|
            define_method(action) do |args:, opts:|
              raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
            end
          end

          def deployable?; true; end

          protected

          def setup_deploy_tasks
            task :deploy do
              desc "Run deployment"
              switch :force, "Force to deploy", short: :f
              action! :deploy
            end
          end
        end

        module Control
          Actions = %i(start_process stop_process kill_process
                       restart_process check_process show_process)
          Actions.each do |action|
            define_method(action) do |args:, opts:|
              raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
            end
          end

          def controllable?; true; end

          def process_monitor_via(monitor, env: "uber/lubmon")
            monitor = monitor.to_s.downcase
            env = env.to_s.downcase
            process_monitor name: monitor, env: env
          end

          protected

          def setup_control_tasks
            task :start do
              desc "Start process"
              action! :start_process
            end

            task :stop do
              desc "Stop process"
              action! :stop_process
            end

            task :restart do
              desc "Restart process"
              action! :restart_process
            end

            task :kill do
              desc "Kill process forcely"
              action! :kill_process
            end

            task :status do
              desc "Check process status"
              action! :check_process
            end

            task :process do
              desc "Show running process if any"
              action! :show_process
            end
          end
        end

        module Crontab
          Actions = %i(update_cronjobs list_cronjobs)
          Actions.each do |action|
            define_method(action) do |args:, opts:|
              raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
            end
          end

          def cronjobs; @cronjobs ||= []; end

          def has_cronjobs?; !cronjobs.empty?; end

          def cronjob(schedule:, command:, output:, disabled: false, roles: nil, hosts: nil, **job)
            if cronjobs.any? { |j| j[:command] == command }
              abort "Aborted! Duplicate cron job is found: #{command}"
            end
            job.merge!(schedule: schedule, command: command, output: output, disabled: disabled)
            roles = Array(roles)
            hosts = Array(hosts)
            servers = select_servers(roles, hosts)
            servers.each { |s| server(s, cronjob: job) }
            cronjobs << job
          end

          protected

          def setup_crontab_tasks
            task :cronjobs_update do
              desc 'Update cron jobs'
              action! :update_cronjobs
            end<commit_msg>Added basic validation for cronjob settings<commit_after>module Luban
  module Deployment
    class Command < Luban::CLI::Command
      module Tasks
        module Install
          Actions = %i(setup build destroy cleanup binstubs
                       show_current show_summary which whence)
          Actions.each do |action|
            define_method(action) do |args:, opts:|
              raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
            end
          end

          def installable?; true; end

          protected

          def setup_install_tasks
            _self = self
            task :setup do
              desc "Setup #{_self.display_name} environment"
              action! :setup
            end

            task :build do
              desc "Build #{_self.display_name} environment"
              switch :force, "Force to build", short: :f
              action! :build
            end

            task :destroy do
              desc "Destroy #{_self.display_name} environment"
              switch :force, "Force to destroy", short: :f, required: true
              action! :destroy
            end

            task :cleanup do
              desc "Clean up temporary files during installation"
              action! :cleanup
            end

            task :binstubs do
              desc "Update binstubs for required packages"
              switch :force, "Force to update binstubs", short: :f
              action! :binstubs
            end

            task :version do
              desc "Show current version for app/required packages"
              action! :show_current
            end

            task :versions do
              desc "Show app/package installation summary"
              action! :show_summary
            end

            task :which do
              desc "Show the real path for the given executable"
              argument :executable, "Executable to which"
              action! :which
            end

            task :whence do
              desc "List packages with the given executable"
              argument :executable, "Executable to whence"
              action! :whence
            end
          end
        end

        module Deploy
          Actions = %i(deploy)
          Actions.each do |action|
            define_method(action) do |args:, opts:|
              raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
            end
          end

          def deployable?; true; end

          protected

          def setup_deploy_tasks
            task :deploy do
              desc "Run deployment"
              switch :force, "Force to deploy", short: :f
              action! :deploy
            end
          end
        end

        module Control
          Actions = %i(start_process stop_process kill_process
                       restart_process check_process show_process)
          Actions.each do |action|
            define_method(action) do |args:, opts:|
              raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
            end
          end

          def controllable?; true; end

          def process_monitor_via(monitor, env: "uber/lubmon")
            monitor = monitor.to_s.downcase
            env = env.to_s.downcase
            process_monitor name: monitor, env: env
          end

          protected

          def setup_control_tasks
            task :start do
              desc "Start process"
              action! :start_process
            end

            task :stop do
              desc "Stop process"
              action! :stop_process
            end

            task :restart do
              desc "Restart process"
              action! :restart_process
            end

            task :kill do
              desc "Kill process forcely"
              action! :kill_process
            end

            task :status do
              desc "Check process status"
              action! :check_process
            end

            task :process do
              desc "Show running process if any"
              action! :show_process
            end
          end
        end

        module Crontab
          Actions = %i(update_cronjobs list_cronjobs)
          Actions.each do |action|
            define_method(action) do |args:, opts:|
              raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
            end
          end

          def cronjobs; @cronjobs ||= []; end

          def has_cronjobs?; !cronjobs.empty?; end

          def cronjob(roles: nil, hosts: nil, **job)
            validate_cronjob(job)
            roles = Array(roles)
            hosts = Array(hosts)
            servers = select_servers(roles, hosts)
            servers.each { |s| server(s, cronjob: job) }
            cronjobs << job
          end

          protected

          def validate_cronjob(job)
            if job[:command].nil?
              abort "Aborted! Cron job command is MISSING."
            end
            if job[:schedule].nil?
              abort "Aborted! Cron job schedule is MISSING for command: #{job[:command]}"
            end
            if cronjobs.any? { |j| j[:command] == job[:command] }
              abort "Aborted! Duplicate command is FOUND: #{job[:command]}"
            end
          end

          def setup_crontab_tasks
            task :cronjobs_update do
              desc 'Update cron jobs'
              action! :update_cronjobs
            end
{'fraction_non_alphanumeric': 0.06740229885057471, 'fraction_numerical': 0.0, 'mean_word_length': 1.3840420868040333, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2997204', 'n_tokens_mistral': 2738, 'n_tokens_neox': 2612, 'n_words': 879}