You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: controller.go
    path of file: ./repos/rill/runtime
    
    the code of the file until where you have to start completion: package runtime

import (
	"context"
	"errors"
	"fmt"
	"runtime"
	"strings"
	"sync"
	"sync/atomic"
	"time"

	runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"
	"github.com/rilldata/rill/runtime/drivers"
	"github.com/rilldata/rill/runtime/pkg/activity"
	"github.com/rilldata/rill/runtime/pkg/dag"
	"github.com/rilldata/rill/runtime/pkg/schedule"
	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/trace"
	"go.uber.org/zap"
	"golang.org/x/exp/maps"
	"google.golang.org/protobuf/proto"
)

// reconcileCancelationTimeout sets a timeout for how long to wait for a reconcile to cancel before stopping the controller with a critical error.
const reconcileCancelationTimeout = 10 * time.Minute

// errCyclicDependency is set as the error on resources that can't be reconciled due to a cyclic dependency
var errCyclicDependency = errors.New("cannot be reconciled due to cyclic dependency")

// errControllerClosed is returned from controller functions that require the controller to be running
var errControllerClosed 
    
func (c *Controller) trySchedule(n *runtimev1.ResourceName) (success bool, err error) {
	r, err := c.catalog.get(n, true, false)
	if err != nil {
		if errors.Is(err, drivers.ErrResourceNotFound) {
			return true, nil
		}
		return false, err
	}

	// Return true if any parents are pending or running.
	// NOTE 1: Only getting parents if it's not a deletion (deleted resources are not tracked in the DAG).
	// NOTE 2: DAG access is safe because markPending ensures we never trySchedule a cyclic resource.
	var parents []*runtimev1.ResourceName
	if r.Meta.DeletedOn == nil {
		parents = c.catalog.dag.Parents(n, true)
	}
	for _, pn := range parents {
		p, err := c.catalog.get(pn, false, false)
		if err != nil {
			return false, fmt.Errorf("internal: error getting present parent %q: %w", nameStr(pn), err)
		}
		if p.Meta.ReconcileStatus != runtimev1.ReconcileStatus_RECONCILE_STATUS_IDLE {
			// When the parent has completed running, processCompletedInvocation will enqueue its children and we'll run again.
			return true, nil
		}
	}

	// We want deletes to run before renames or regular reconciles.
	// And we want renames to run before regular reconciles.
	// Return false if there are deleted or renamed resources, and this isn't one of them.
	// (The resource will be kept in the queue and retried next time processQueue runs.)
	if r.Meta.DeletedOn == nil {
		if len(c.catalog.deleted) != 0 {
			return false, nil
		}

		if r.Meta.RenamedFrom == nil && len(c.catalog.renamed) != 0 {
			return false, nil
		}
	}

	// Invoke
	err = c.invoke(r)
	if err != nil {
		return false, err
	}
	return true, nil
}