<commit_before>package job

import (
	"fmt"

	"github.com/appscode/go/log"
	api "github.com/kubedb/apimachinery/apis/kubedb/v1alpha1"
	"github.com/kubedb/apimachinery/client/clientset/versioned/typed/kubedb/v1alpha1/util"
	"github.com/kubedb/apimachinery/pkg/eventer"
	batch "k8s.io/api/batch/v1"
	core "k8s.io/api/core/v1"
	kerr "k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	clientsetscheme "k8s.io/client-go/kubernetes/scheme"
	"k8s.io/client-go/tools/reference"
)

func (c *Controller) completeJob(job *batch.Job) error {
	deletePolicy := metav1.DeletePropagationBackground
	err := c.Client.BatchV1().Jobs(job.Namespace).Delete(job.Name, &metav1.DeleteOptions{
		PropagationPolicy: &deletePolicy,
	})

	if err != nil && !kerr.IsNotFound(err) {
		return fmt.Errorf("failed to delete job: %s, reason: %s", job.Name, err)
	}

	jobType := job.Annotations[api.AnnotationJobType]
	if jobType == api.JobTypeBackup {
		return c.handleBackupJob(job)
	} else if jobType == api.JobTypeRestore {
		return c.handleRestoreJob(job)
	}

	return nil
}

func (c *Controller) handleBackupJob(job *batch.Job) error {
	for _, o := range job.OwnerReferences {
		if o.Kind == api.ResourceKindSnapshot {
			snapshot, err := c.ExtClient.Snapshots(job.Namespace).Get(o.Name, metav1.GetOptions{})
			if err != nil {
				return err
			}

			jobSucceeded := job.Status.Succeeded > 0

			if _, err := util.UpdateSnapshotStatus(c.ExtClient, snapshot, func(in *api.SnapshotStatus) *api.SnapshotStatus {
				if jobSucceeded {<commit_msg>Take 'AnnotationJobType' from labels (#267)<commit_after>package job

import (
	"fmt"

	"github.com/appscode/go/log"
	api "github.com/kubedb/apimachinery/apis/kubedb/v1alpha1"
	"github.com/kubedb/apimachinery/client/clientset/versioned/typed/kubedb/v1alpha1/util"
	"github.com/kubedb/apimachinery/pkg/eventer"
	batch "k8s.io/api/batch/v1"
	core "k8s.io/api/core/v1"
	kerr "k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	clientsetscheme "k8s.io/client-go/kubernetes/scheme"
	"k8s.io/client-go/tools/reference"
)

func (c *Controller) completeJob(job *batch.Job) error {
	deletePolicy := metav1.DeletePropagationBackground
	err := c.Client.BatchV1().Jobs(job.Namespace).Delete(job.Name, &metav1.DeleteOptions{
		PropagationPolicy: &deletePolicy,
	})

	if err != nil && !kerr.IsNotFound(err) {
		return fmt.Errorf("failed to delete job: %s, reason: %s", job.Name, err)
	}

	jobType := job.Labels[api.AnnotationJobType]
	if jobType == api.JobTypeBackup {
		return c.handleBackupJob(job)
	} else if jobType == api.JobTypeRestore {
		return c.handleRestoreJob(job)
	}

	return nil
}

func (c *Controller) handleBackupJob(job *batch.Job) error {
	for _, o := range job.OwnerReferences {
		if o.Kind == api.ResourceKindSnapshot {
			snapshot, err := c.ExtClient.Snapshots(job.Namespace).Get(o.Name, metav1.GetOptions{})
			if err != nil {
				return err
			}

			jobSucceeded := job.Status.Succeeded > 0

			if _, err := util.UpdateSnapshotStatus(c.ExtClient, snapshot, func(in *api.SnapshotStatus) *api.SnapshotStatus {
				if jobSucceeded {
{'fraction_non_alphanumeric': 0.1421238370227783, 'fraction_numerical': 0.01315367340391402, 'mean_word_length': 4.499118165784832, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6782841', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1214, 'n_words': 196}