task (God)

    # File lib/god.rb, line 235
      def self.task(klass = Task)
        self.internal_init

        t = klass.new
        yield(t)

        # do the post-configuration
        t.prepare

        # if running, completely remove the watch (if necessary) to
        # prepare for the reload
        existing_watch = self.watches[t.name]
        if self.running && existing_watch
          self.pending_watch_states[existing_watch.name] = existing_watch.state
          self.unwatch(existing_watch)
        end

        # ensure the new watch has a unique name
        if self.watches[t.name] || self.groups[t.name]
          abort "Task name '#{t.name}' already used for a Task or Group"
        end

        # ensure watch is internally valid
        t.valid? || abort("Task '#{t.name}' is not valid (see above)")

        # add to list of watches
        self.watches[t.name] = t

        # add to pending watches
        self.pending_watches << t

        # add to group if specified
        if t.group
          # ensure group name hasn't been used for a watch already
          if self.watches[t.group]
            abort "Group name '#{t.group}' already used for a Task"
          end

          self.groups[t.group] ||= []
          self.groups[t.group] << t
        end

        # register watch
        t.register!

        # log
        if self.running && existing_watch
          applog(t, :info, "#{t.name} Reloaded config")
        elsif self.running
          applog(t, :info, "#{t.name} Loaded config")
        end
      end