Reflect the fact that a job has been killed in redis
193360
def kill
      self.status = 'killed'

      Sidekiq.redis do |conn|
        conn.multi do
          save
          conn.zrem(self.class.kill_key, self.jid)
        end
      end
    end
132591
def done?
      return (
        get_jobs_by_status(Executor::STATUS_NONE).size == 0 &&
        get_jobs_by_status(Executor::STATUS_RUNNING).size == 0 &&
        get_jobs_by_status(Executor::STATUS_DONE).size > 0
      )
    end
144187
def enqueue(self, job):
    
    if job.queue_name():
      raise EnqueueError("job %s already queued!" % job.job_id)
    new_len = self.redis.lpush(self.queue_name, job.serialize())
    job.notify_queued(self)
    return new_len
1281336
def expireat(self, key, when):
        """"""
        expire_time = datetime.fromtimestamp(when)
        key = self._encode(key)
        if key in self.redis:
            self.timeouts[key] = expire_time
            return True
        return False
43519
def mark_process_dead(pid, path=None):
    """"""
    if path is None:
        path = os.environ.get('prometheus_multiproc_dir')
    for f in glob.glob(os.path.join(path, 'gauge_livesum_{0}.db'.format(pid))):
        os.remove(f)
    for f in glob.glob(os.path.join(path, 'gauge_liveall_{0}.db'.format(pid))):
        os.remove(f)
1195994
def handle(self, *args, **kwargs):
        """"""
        listener = ExecutorListener(redis_params=getattr(settings, 'FLOW_MANAGER', {}).get('REDIS_CONNECTION', {}))

        def _killer(signum, frame):
            """Kill the listener on receipt of a signal."""
            listener.terminate()
        signal(SIGINT, _killer)
        signal(SIGTERM, _killer)

        async def _runner():
            """Run the listener instance."""
            if kwargs['clear_queue']:
                await listener.clear_queue()
            async with listener:
                pass

        loop = asyncio.new_event_loop()
        loop.run_until_complete(_runner())
        loop.close()
1077701
def refresh(self):
    """"""
    if self.status == 'executing' and self.array:
      new_result = 0
      for array_job in self.array:
        if array_job.status == 'failure' and new_result is not None:
          new_result = array_job.result
        elif array_job.status not in ('success', 'failure'):
          new_result = None
      if new_result is not None:
        self.status = 'success' if new_result == 0 else 'failure'
        self.result = new_result
158387
async def main():
    redis = await create_pool(RedisSettings())

    # no id, random id will be generated
    job1 = await redis.enqueue_job('the_task')
    print(job1)
    

    # random id again, again the job will be enqueued and a job will be returned
    job2 = await redis.enqueue_job('the_task')
    print(job2)
    """
    >  <arq job 7d2163c056e54b62a4d8404921094f05>
    """

    # custom job id, job will be enqueued
    job3 = await redis.enqueue_job('the_task', _job_id='foobar')
    print(job3)
    """
    >  <arq job foobar>
    """

    # same custom job id, job will not be enqueued and enqueue_job will return None
    job4 = await redis.enqueue_job('the_task', _job_id='foobar')
    print(job4)
    """
    >  None
    """
824716
public function doneWorking()
    {
        $this->currentJob = null;
        $this->working = false;
        $this->resqueInstance->stats->incr('processed');
        $this->resqueInstance->stats->incr('processed:' . (string)$this);
        $this->resqueInstance->redis->del($this->workerName() . ':' . (string)$this);
    }
988618
def mark_dead(self, proxy, _time=None):
        
        if proxy not in self.proxies:
            logger.warn("Proxy <%s> was not found in proxies list" % proxy)
            return

        if proxy in self.good:
            logger.debug("GOOD proxy became DEAD: <%s>" % proxy)
        else:
            logger.debug("Proxy <%s> is DEAD" % proxy)

        self.unchecked.discard(proxy)
        self.good.discard(proxy)
        self.dead.add(proxy)

        now = _time or time.time()
        state = self.proxies[proxy]
        state.backoff_time = self.backoff(state.failed_attempts)
        state.next_check = now + state.backoff_time
        state.failed_attempts += 1
446691
def __die(self, synchronous=False):
        
        already_killed = self.__killed
        self.__killed = True
        if self.__id and not already_killed:
            address = _CursorAddress(
                self.__address, self.__collection.full_name)
            if synchronous:
                self.__collection.database.client._close_cursor_now(
                    self.__id, address, session=self.__session)
            else:
                # The cursor will be closed later in a different session.
                self.__collection.database.client._close_cursor(
                    self.__id, address)
        self.__end_session(synchronous)
345215
def remove_raw_jobs(self, params_list):
        

        if len(params_list) == 0:
            return

        # ZSET
        if self.is_sorted:
            context.connections.redis.zrem(self.redis_key, *iter(params_list))

        # SET
        elif self.is_set:
            context.connections.redis.srem(self.redis_key, *params_list)

        else:
            # O(n)! Use with caution.
            for k in params_list:
                context.connections.redis.lrem(self.redis_key, 1, k)

        context.metric("queues.%s.removed" % self.id, len(params_list))
        context.metric("queues.all.removed", len(params_list))
289196
def expire(sec)
      tasks.each { |task| task.expire(sec) }
      slaves.each { |slave| slave.expire(sec) }
      worker_logs.each { |worker_log| worker_log.expire(sec) }
      RRRSpec.redis.expire(key, sec)
      RRRSpec.redis.expire(RRRSpec.make_key(key, 'log'), sec)
      RRRSpec.redis.expire(RRRSpec.make_key(key, 'slave'), sec)
      RRRSpec.redis.expire(RRRSpec.make_key(key, 'worker_log'), sec)
      RRRSpec.redis.expire(RRRSpec.make_key(key, 'task_queue'), sec)
      RRRSpec.redis.expire(RRRSpec.make_key(key, 'tasks'), sec)
      RRRSpec.redis.expire(RRRSpec.make_key(key, 'tasks_left'), sec)
    end
710257
def __die(self, synchronous=False):
        
        if self.__id and not self.__killed:
            if self.__exhaust and self.__exhaust_mgr:
                # If this is an exhaust cursor and we haven't completely
                # exhausted the result set we *must* close the socket
                # to stop the server from sending more data.
                self.__exhaust_mgr.sock.close()
            else:
                address = _CursorAddress(
                    self.__address, self.__collection.full_name)
                if synchronous:
                    self.__collection.database.client._close_cursor_now(
                        self.__id, address)
                else:
                    self.__collection.database.client.close_cursor(
                        self.__id, address)
        if self.__exhaust and self.__exhaust_mgr:
            self.__exhaust_mgr.close()
        self.__killed = True
700986
def mark_job_as_completed(job_id, data=None):
    
    update_dict = {
        "status": "complete",
        "data": json.dumps(data),
        "finished_timestamp": datetime.datetime.now(),
    }
    _update_job(job_id, update_dict)
1099056
def failed
      v = RRRSpec.redis.hget(key, 'failed')
      v.present? ? v.to_i : nil
    end
1058773
def cleanup_dead_jobs():
    
    from .models import WooeyJob

    # Get active tasks from Celery
    inspect = celery_app.control.inspect()
    active_tasks = {task['id'] for worker, tasks in six.iteritems(inspect.active()) for task in tasks}

    # find jobs that are marked as running but not present in celery's active tasks
    active_jobs = WooeyJob.objects.filter(status=WooeyJob.RUNNING)
    to_disable = set()
    for job in active_jobs:
        if job.celery_id not in active_tasks:
            to_disable.add(job.pk)

    WooeyJob.objects.filter(pk__in=to_disable).update(status=WooeyJob.FAILED)