<commit_before>package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"io/ioutil"
	"os"
	"os/signal"
	"sync"
	"time"

	"github.com/golang/glog"
	honeybadger "github.com/honeybadger-io/honeybadger-go"
	"github.com/joho/godotenv"
	"github.com/pkg/errors"
	"github.com/robfig/cron"
	"gopkg.in/yaml.v2"
	"k8s.io/client-go/1.4/kubernetes"
	"k8s.io/client-go/1.4/pkg/api"
	"k8s.io/client-go/1.4/pkg/apis/batch/v1"
	"k8s.io/client-go/1.4/pkg/fields"
	"k8s.io/client-go/1.4/rest"
	"k8s.io/client-go/1.4/tools/clientcmd"
)

var (
	kubeClient   *kubernetes.Clientset
	manager      Manager
	configPath   string
	configDir    string
	scheduleName string
)

func init() {
	flag.StringVar(&configDir, "config", ".", "path to schedule yaml")
	flag.StringVar(&scheduleName, "schedule-name", "schedule.yml", "name of schedule config file")
	flag.StringVar(&configPath, "kubeconfig", "", "absolute path to kubernetes credentials dir")

	if configPath == "" {
		configPath = os.Getenv("KUBE_CONFIG_PATH")
	}

	if os.Getenv("SCHEDULE_NAME") != "" {
		scheduleName = os.Getenv("SCHEDULE_NAME")
	}

	configureHoneybadger()
}

func main() {
	flag.Parse()
	godotenv.Load()
	glog.Info("Kube Scheduler")

	var err error
	kubeClient, err = createKubernetesClient()
	if err != nil {
		honeybadger.Notify(
			"Scheduler could not create kubernetes client",
			honeybadger.Context{"error": err}, honeybadger.Fingerprint{time.Now().String()},
		)
		glog.Fatalf("Could not create kubernetes client: %s", err)
	}

	manager, err = createScheduleManager(filePath(scheduleName))
	if err != nil {
		honeybadger.Notify(
			"Scheduler could not create job manager",
			honeybadger.Context{"error": err}, honeybadger.Fingerprint{time.Now().String()},
		)
		glog.Fatalf("Could not create manager: %s", err)
	}

	cronManager := cron.New()
	for name, job := range manager.jobList {
		glog.Infof("Adding job %s (%s) with schedule %s", name, job.Description, job.Cron)
		go func(name string, job Job) {
			cronManager.AddFunc(job.Cron, func() {
				glog.Infof("Running %s...", name)
				if err := job.Run(); err != nil {
					glog.Warningf("Unable to create & run job: %s", err)
					honeybadger.Notify(fmt.Sprintf("Unable to schedule %s", name), honeybadger.Context{"error": err})<commit_msg>added bypass for empty schedules<commit_after>package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"io/ioutil"
	"os"
	"os/signal"
	"sync"
	"time"

	"github.com/golang/glog"
	honeybadger "github.com/honeybadger-io/honeybadger-go"
	"github.com/joho/godotenv"
	"github.com/pkg/errors"
	"github.com/robfig/cron"
	"gopkg.in/yaml.v2"
	"k8s.io/client-go/1.4/kubernetes"
	"k8s.io/client-go/1.4/pkg/api"
	"k8s.io/client-go/1.4/pkg/apis/batch/v1"
	"k8s.io/client-go/1.4/pkg/fields"
	"k8s.io/client-go/1.4/rest"
	"k8s.io/client-go/1.4/tools/clientcmd"
)

var (
	kubeClient   *kubernetes.Clientset
	manager      Manager
	configPath   string
	configDir    string
	scheduleName string
)

func init() {
	flag.StringVar(&configDir, "config", ".", "path to schedule yaml")
	flag.StringVar(&scheduleName, "schedule-name", "schedule.yml", "name of schedule config file")
	flag.StringVar(&configPath, "kubeconfig", "", "absolute path to kubernetes credentials dir")

	if configPath == "" {
		configPath = os.Getenv("KUBE_CONFIG_PATH")
	}

	if os.Getenv("SCHEDULE_NAME") != "" {
		scheduleName = os.Getenv("SCHEDULE_NAME")
	}

	configureHoneybadger()
}

func main() {
	flag.Parse()
	godotenv.Load()
	glog.Info("Kube Scheduler")

	var err error
	kubeClient, err = createKubernetesClient()
	if err != nil {
		honeybadger.Notify(
			"Scheduler could not create kubernetes client",
			honeybadger.Context{"error": err}, honeybadger.Fingerprint{time.Now().String()},
		)
		glog.Fatalf("Could not create kubernetes client: %s", err)
	}

	manager, err = createScheduleManager(filePath(scheduleName))
	if err != nil {
		honeybadger.Notify(
			"Scheduler could not create job manager",
			honeybadger.Context{"error": err}, honeybadger.Fingerprint{time.Now().String()},
		)
		glog.Fatalf("Could not create manager: %s", err)
	}

	cronManager := cron.New()
	// loop over the jobs and add to the cronManager
	for name, job := range manager.jobList {
		if job.Cron == "" {
			glog.Infof("Ignoring job %s (%s) without schedule", name, job.Description)
			continue // Skip adding empty schedules to the cronManager
		}
		glog.Infof("Adding job %s (%s) with schedule %s", name, job.Description, job.Cron)
		go func(name string, job Job) {
			cronManager.AddFunc(job.Cron, func() {
				glog.Infof("Running %s...", name)
				if err := job.Run(); err != nil {
					glog.Warningf("Unable to create & run job: %s", err)
					honeybadger.Notify(fmt.Sprintf("Unable to schedule %s", name), honeybadger.Context{"error": err})
{'fraction_non_alphanumeric': 0.15951827593492499, 'fraction_numerical': 0.008451299387280795, 'mean_word_length': 4.145652173913043, 'pattern_counts': {'":': 6, '<': 3, '<?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': '1630347', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1797, 'n_words': 366}