// Deregister is used to remove an existing job. If purge is set to true, the job
// is deregistered and purged from the system versus still being queryable and
// eventually GC'ed from the system. Most callers should not specify purge.
553112
func (j *Jobs) Deregister(jobID string, purge bool, q *WriteOptions) (string, *WriteMeta, error) {
	var resp JobDeregisterResponse
	wm, err := j.client.delete(fmt.Sprintf("/v1/job/%v?purge=%t", jobID, purge), &resp, q)
	if err != nil {
		return "", nil, err
	}
	return resp.EvalID, wm, nil
}
364892
func (t *LinodeService) Shutdown(linodeId int) (*JobResponse, error) {
	u := &url.Values{}
	u.Add("LinodeID", strconv.Itoa(linodeId))
	v := JobResponse{}
	if err := t.client.do("linode.shutdown", u, &v.Response); err != nil {
		return nil, err
	}

	if err := json.Unmarshal(v.RawData, &v.JobId); err != nil {
		return nil, err
	}
	return &v, nil
}
287991
func (cgi *ConsumergroupInstance) Deregister() error {
	node := fmt.Sprintf("%s/consumers/%s/ids/%s", cgi.cg.kz.conf.Chroot, cgi.cg.Name, cgi.ID)
	exists, stat, err := cgi.cg.kz.conn.Exists(node)
	if err != nil {
		return err
	} else if !exists {
		return ErrInstanceNotRegistered
	}

	err = cgi.cg.kz.conn.Delete(node, stat.Version)
	if err == zk.ErrNoNode {
		return ErrInstanceNotRegistered
	}
	return err
}
528334
func (a *renderedJobListArchive) Delete() error {
	err := a.fs.RemoveAll(a.path)
	if err != nil {
		return bosherr.WrapErrorf(err, "Deleting rendered job list archive '%s'", a.path)
	}
	return nil
}
416076
func (h *serviceHook) deregister() {
	taskServices := h.getTaskServices()
	h.consul.RemoveTask(taskServices)

	// Canary flag may be getting flipped when the alloc is being
	// destroyed, so remove both variations of the service
	taskServices.Canary = !taskServices.Canary
	h.consul.RemoveTask(taskServices)

}
454216
func (c *jobController) IsCleaningJobRunning(pvName string) bool {
	jobName := generateCleaningJobName(pvName)
	job, err := c.jobLister.Jobs(c.namespace).Get(jobName)
	if errors.IsNotFound(err) {
		return false
	}

	if err != nil {
		glog.Warningf("Failed to check whether job %s is running (%s). Assuming its still running.",
			jobName, err)
		return true
	}

	return job.Status.Succeeded <= 0
}
1000577
func (m *Main) Demote() error {
	m.mu.Lock()
	defer m.mu.Unlock()

	m.logger.Println("demotion requested")

	var leaderAddr string
	if m.store != nil {
		leaderAddr := m.store.Leader()
		if leaderAddr == "" {
			return server.ErrNoKnownLeader
		}
	} else {
		leader, err := discoverd.DefaultClient.RaftLeader()
		if err != nil || (err == nil && leader.Host == "") {
			return fmt.Errorf("failed to get leader address from configured peers")
		}
		leaderAddr = leader.Host
	}

	// Update the dns server to use proxy store
	if m.dnsServer != nil {
		m.dnsServer.SetStore(&server.ProxyStore{Peers: m.peers})
	}

	// Set handler into proxy mode
	m.handler.Proxy.Store(true)

	// If we fail from here on out we should attempt to rollback
	rollback := func() {
		if m.dnsServer != nil {
			m.dnsServer.SetStore(m.store)
		}
		m.handler.Proxy.Store(false)
	}

	// If we are the leader remove ourselves directly,
	// otherwise request the leader remove us from the peer set.
	if leaderAddr == m.advertiseAddr {
		if err := m.store.RemovePeer(m.advertiseAddr); err != nil {
			rollback()
			return err
		}
	} else {
		if err := discoverd.DefaultClient.RaftRemovePeer(m.advertiseAddr); err != nil {
			rollback()
			return err
		}
	}

	// Close the raft store.
	if m.store != nil {
		m.store.Close()
		m.store = nil
	}
	m.handler.Store = nil

	m.logger.Println("demoted successfully")
	return nil
}
36456
func (r *HandlerRegistry) Deregister(cname string) error {
	chaincodeLogger.Debugf("deregister handler: %s", cname)

	r.mutex.Lock()
	handler := r.handlers[cname]
	delete(r.handlers, cname)
	delete(r.launching, cname)
	r.mutex.Unlock()

	if handler == nil {
		return errors.Errorf("could not find handler: %s", cname)
	}

	handler.Close()

	chaincodeLogger.Debugf("deregistered handler with key: %s", cname)
	return nil
}
1017667
func (c *Client) RetryDeadJob(diedAt int64, jobID string) error {
	// Get queues for job names
	queues, err := c.Queues()
	if err != nil {
		logError("client.retry_all_dead_jobs.queues", err)
		return err
	}

	// Extract job names
	var jobNames []string
	for _, q := range queues {
		jobNames = append(jobNames, q.JobName)
	}

	script := redis.NewScript(len(jobNames)+1, redisLuaRequeueSingleDeadCmd)

	args := make([]interface{}, 0, len(jobNames)+1+3)
	args = append(args, redisKeyDead(c.namespace)) // KEY[1]
	for _, jobName := range jobNames {
		args = append(args, redisKeyJobs(c.namespace, jobName)) // KEY[2, 3, ...]
	}
	args = append(args, redisKeyJobsPrefix(c.namespace)) // ARGV[1]
	args = append(args, nowEpochSeconds())
	args = append(args, diedAt)
	args = append(args, jobID)

	conn := c.pool.Get()
	defer conn.Close()

	cnt, err := redis.Int64(script.Do(conn, args...))
	if err != nil {
		logError("client.retry_dead_job.do", err)
		return err
	}

	if cnt == 0 {
		return ErrNotRetried
	}

	return nil
}
904767
func (client *client) deregisterBroker(broker *Broker) {
	client.lock.Lock()
	defer client.lock.Unlock()

	if len(client.seedBrokers) > 0 && broker == client.seedBrokers[0] {
		client.deadSeeds = append(client.deadSeeds, broker)
		client.seedBrokers = client.seedBrokers[1:]
	} else {
		// we do this so that our loop in `tryRefreshMetadata` doesn't go on forever,
		// but we really shouldn't have to; once that loop is made better this case can be
		// removed, and the function generally can be renamed from `deregisterBroker` to
		// `nextSeedBroker` or something
		Logger.Printf("client/brokers deregistered broker #%d at %s", broker.ID(), broker.Addr())
		delete(client.brokers, broker.ID())
	}
}
1135002
func (a *renderedJobListArchive) DeleteSilently() {
	err := a.Delete()
	if err != nil {
		a.logger.Error(a.logTag, "Failed to delete rendered job list archive: %s", err.Error())
	}
}
521346
func (s HashExpireyStrategy) Purge(location, ID string, pool *redis.Pool) error {
	cnx := pool.Get()
	defer cnx.Close()

	if _, err := cnx.Do("HDEL", location, ID); err != nil {
		return err
	}

	return nil
}
200184
func (l *LogWriter) DeregisterHandler(lh LogHandler) {
	l.Lock()
	defer l.Unlock()
	delete(l.handlers, lh)
}
1019033
func (c *Client) DeleteRetryJob(retryAt int64, jobID string) error {
	ok, _, err := c.deleteZsetJob(redisKeyRetry(c.namespace), retryAt, jobID)
	if err != nil {
		return err
	}
	if !ok {
		return ErrNotDeleted
	}
	return nil
}
1025232
func (l *State) deleteService(id string) error {
	if id == "" {
		return fmt.Errorf("ServiceID missing")
	}

	req := structs.DeregisterRequest{
		Datacenter:   l.config.Datacenter,
		Node:         l.config.NodeName,
		ServiceID:    id,
		WriteRequest: structs.WriteRequest{Token: l.serviceToken(id)},
	}
	var out struct{}
	err := l.Delegate.RPC("Catalog.Deregister", &req, &out)
	switch {
	case err == nil || strings.Contains(err.Error(), "Unknown service"):
		delete(l.services, id)
		l.logger.Printf("[INFO] agent: Deregistered service %q", id)
		return nil

	case acl.IsErrPermissionDenied(err), acl.IsErrNotFound(err):
		// todo(fs): mark the service to be in sync to prevent excessive retrying before next full sync
		// todo(fs): some backoff strategy might be a better solution
		l.services[id].InSync = true
		l.logger.Printf("[WARN] agent: Service %q deregistration blocked by ACLs", id)
		metrics.IncrCounter([]string{"acl", "blocked", "service", "deregistration"}, 1)
		return nil

	default:
		l.logger.Printf("[WARN] agent: Deregistering service %q failed. %s", id, err)
		return err
	}
}
697780
func (c *jobController) RemoveJob(pvName string) (CleanupState, *time.Time, error) {
	jobName := generateCleaningJobName(pvName)
	job, err := c.jobLister.Jobs(c.namespace).Get(jobName)
	if err != nil {
		if errors.IsNotFound(err) {
			return CSNotFound, nil, nil
		}
		return CSUnknown, nil, fmt.Errorf("Failed to check whether job %s has succeeded. Error - %s",
			jobName, err.Error())
	}

	var startTime *time.Time
	if startTimeStr, ok := job.Annotations[StartTimeAnnotation]; ok {
		parsedStartTime, err := time.Parse(time.RFC3339Nano, startTimeStr)
		if err == nil {
			startTime = &parsedStartTime
		} else {
			glog.Errorf("Failed to parse start time %s: %v", startTimeStr, err)
		}
	}

	if job.Status.Succeeded == 0 {
		// Jobs has not yet succeeded. We assume failed jobs to be still running, until addressed by admin.
		return CSUnknown, nil, fmt.Errorf("Error deleting Job %q: Cannot remove job that has not succeeded", job.Name)
	}

	if err := c.RuntimeConfig.APIUtil.DeleteJob(job.Name, c.namespace); err != nil {
		return CSUnknown, nil, fmt.Errorf("Error deleting Job %q: %s", job.Name, err.Error())
	}

	return CSSucceeded, startTime, nil
}
522334
func (r *Registrar) DeleteRegistration() error {
	if r == nil || r.user == nil {
		return errors.New("acme: cannot unregister a nil client or user")
	}

	log.Infof("acme: Deleting account for %s", r.user.GetEmail())

	return r.core.Accounts.Deactivate(r.user.GetRegistration().URI)
}