Make a recurring job in this queue
 Options include:
 => priority (int)
 => tags (array of strings)
 => retries (int)
 => offset (int)
325540
def recur(klass, data, interval, opts = {})
      opts = job_options(klass, data, opts)
      @client.call(
        'recur',
        @name,
        (opts[:jid] || Qless.generate_jid),
        klass.is_a?(String) ? klass : klass.name,
        JSON.generate(data),
        'interval', interval, opts.fetch(:offset, 0),
        'priority', opts.fetch(:priority, 0),
        'tags', JSON.generate(opts.fetch(:tags, [])),
        'retries', opts.fetch(:retries, 5),
        'backlog', opts.fetch(:backlog, 0)
      )
    end
621073
public static void main(String[] args) {
    FixedPrioritiesPriorityQueue<String> pq = new FixedPrioritiesPriorityQueue<String>();
    System.out.println(pq);
    pq.add("one",1);
    System.out.println(pq);
    pq.add("three",3);
    System.out.println(pq);
    pq.add("one",1.1);
    System.out.println(pq);
    pq.add("two",2);
    System.out.println(pq);
    System.out.println(pq.toString(2));
    while (pq.hasNext()) {
      System.out.println(pq.next());
    }
  }
764259
function () {
    var self = this;
    if (self._pollsScheduledButNotStarted > 0)
      return;
    ++self._pollsScheduledButNotStarted;
    self._taskQueue.queueTask(function () {
      self._pollMongo();
    });
  }
1096317
public void runNextPendingCommand() {
    long peakDelay = mQueue.getHeadDelay();
    ScheduledTask<?> scheduledTask = mQueue.pop();
    scheduledTask.run();
    if (!scheduledTask.isCancelled() && scheduledTask.isRepeat()) {
      mQueue.add(scheduledTask.mRepeatDelay + peakDelay, scheduledTask);
    }
  }
1178715
def reenqueue(self, batch):
        """"""
        now = time.time()
        batch.attempts += 1
        batch.last_attempt = now
        batch.last_append = now
        batch.set_retry()
        assert batch.topic_partition in self._tp_locks, 'TopicPartition not in locks dict'
        assert batch.topic_partition in self._batches, 'TopicPartition not in batches'
        dq = self._batches[batch.topic_partition]
        with self._tp_locks[batch.topic_partition]:
            dq.appendleft(batch)
1333330
private void scheduleRetry() {
        Context appContext = getApplicationContext();
        long nextRetry = System.currentTimeMillis() + RetryPolicy.incrementAndGetTime(appContext);
        scheduleWingsService(appContext, nextRetry);
    }
1184404
def enqueue item, priority=0
      raise RangeError.new("priority #{priority} is greater than queue size") if priority > self.size
      @array.push PQNode.new(item, priority)
      @array.sort! { |a, b| a.priority <=> b.priority }
    end
212841
def start
      self.sort_queues!

      for i in (1..max_threads)
        @threads << Thread.new(i) do
          worker = QueueWorker.new
          worker.delay = @delay
          worker.retry_count = @retry_count
          worker.run
        end
      end
    end
1024461
def pending_tasks(self, res):
        ""
        jobs, lock = self._jobs
        with lock:
            return jobs[res].copy()
1027673
def queue_future_jobs
      tasks.each do |task|
        # Schedule the new run times using the future job wrapper.
        new_run_times = task.future_run_times - task.existing_run_times
        new_run_times.each do |time|
          SimpleScheduler::FutureJob.set(queue: @queue_name, wait_until: time)
                                    .perform_later(task.params, time.to_i)
        end
      end
    end
45341
def enqueue(self, payload, interval, job_id,
                queue_id, queue_type='default', requeue_limit=None):
        
        # validate all the input
        if not is_valid_interval(interval):
            raise BadArgumentException('`interval` has an invalid value.')

        if not is_valid_identifier(job_id):
            raise BadArgumentException('`job_id` has an invalid value.')

        if not is_valid_identifier(queue_id):
            raise BadArgumentException('`queue_id` has an invalid value.')

        if not is_valid_identifier(queue_type):
            raise BadArgumentException('`queue_type` has an invalid value.')

        if requeue_limit is None:
            requeue_limit = self._default_job_requeue_limit

        if not is_valid_requeue_limit(requeue_limit):
            raise BadArgumentException('`requeue_limit` has an invalid value.')

        try:
            serialized_payload = serialize_payload(payload)
        except TypeError as e:
            raise BadArgumentException(e.message)

        timestamp = str(generate_epoch())

        keys = [
            self._key_prefix,
            queue_type
        ]

        args = [
            timestamp,
            queue_id,
            job_id,
            '"%s"' % serialized_payload,
            interval,
            requeue_limit
        ]

        self._lua_enqueue(keys=keys, args=args)

        response = {
            'status': 'queued'
        }
        return response
1189788
def maybe_put_task(self):
        """"""
        try:
            task = next(self.tasks)
        except StopIteration:
            pass
        else:
            log.debug('Putting %s on queue', task)
            self.task_queue.put(task)
539353
def run_with_retry(&block)
      Log.debug "Running job '#{@job_id}' with status '#{@status}'"
      # If we are not the first job in this group, wait @delay
      ChimpDaemon.instance.semaphore.synchronize do
        if @group.started >= @concurrency && @delay.nonzero?
          Log.info "[#{@job_uuid}] Sleeping #{@delay} seconds between tasks"
          sleep @delay
        end
        @group.started += 1
      end

      @status = STATUS_RUNNING
      @time_start = Time.now

      Log.info self.describe_work_start unless @quiet

      #
      # The inner level of exception handling here tries to catch anything
      # that can be easily retired or failed-- normal exceptions.
      #
      # The outer level of exception handling handles weird stuff; for example,
      # sometimes rest_connection raises RuntimeError exceptions...
      #
      # This fixes acu75562.
      #
      begin
        begin
          yield if not @dry_run

          if @owner != nil
            @status = STATUS_DONE
            @group.job_completed
          else
            Log.warn "[#{@job_uuid}][#{@job_id}] Ownership of job_id #{job_id} lost. User cancelled operation?"
          end

        rescue SystemExit, Interrupt => ex
          $stderr.puts 'Exiting!'
          raise ex

        rescue Interrupt => ex
          name = @array['name'] if @array
          name = @server['name'] || @server['nickname'] if @server
          Log.error self.describe_work_error

          if @retry_count > 0
            @status = STATUS_RETRYING
            Log.error "[#{@job_uuid}][#{@job_id}] Error executing on \"#{name}\". Retrying in #{@retry_sleep} seconds..."
            @retry_count -= 1
            sleep @retry_sleep
            retry
          end

          @status = STATUS_ERROR
          @error = ex
          Log.error "[#{@job_uuid}][#{@job_id}] Error executing on \"#{name}\": #{ex}"

        ensure
          @time_end = Time.now
          Log.info self.describe_work_done unless @quiet
        end

      rescue RuntimeError => ex
        err = ex.message + "IP: #{@server.params["ip_address"]}\n" if @server.params['ip_address']
        err += " Group: #{@group.group_id}\n" if @group.group_id
        err += " Notes: #{@job_notes}\n" if @job_notes
        err += " Notes: #{@job_notes}\n" if @job_notes
        Log.error "[#{@job_uuid}][#{@job_id}] Caught RuntimeError: #{err} Job failed.\n"
        @status = STATUS_ERROR
        @error = ex
      end
    end
474222
def reload(self, schedule):
        '''
        
        '''
        # Remove all jobs from self.intervals
        self.intervals = {}

        if 'schedule' in schedule:
            schedule = schedule['schedule']
        self.opts.setdefault('schedule', {}).update(schedule)
108216
def requeue(self):
        """"""
        job_requeue_interval = float(
            self.config.get('sharq', 'job_requeue_interval'))
        while True:
            self.sq.requeue()
            gevent.sleep(job_requeue_interval / 1000.00)
79754
def re_enqueue(self, item):
        """"""
        if 'retries' in item:
            retries = item['retries']
            if retries >= self.MAX_RETRIES:
                log.warn("Failed to execute {} after {} retries, give it "
                         " up.".format(item['method'], retries))
            else:
                retries += 1
                item['retries'] = retries
                self._q.put_nowait(item)
        else:
            item['retries'] = 1
            self._q.put_nowait(item)
67527
def queue(self, new_job_id = None, new_job_name = None, queue_name = None):
    """"""
    # update the job id (i.e., when the job is executed in the grid)
    if new_job_id is not None:
      self.id = new_job_id

    if new_job_name is not None:
      self.name = new_job_name

    if queue_name is not None:
      self.queue_name = queue_name

    new_status = 'queued'
    self.result = None
    # check if we have to wait for another job to finish
    for job in self.get_jobs_we_wait_for():
      if job.status not in ('success', 'failure'):
        new_status = 'waiting'
      elif self.stop_on_failure and job.status == 'failure':
        new_status = 'failure'

    # reset the queued jobs that depend on us to waiting status
    for job in self.get_jobs_waiting_for_us():
      if job.status == 'queued':
        job.status = 'failure' if new_status == 'failure' else 'waiting'

    self.status = new_status
    for array_job in self.array:
      if array_job.status not in ('success', 'failure'):
        array_job.status = new_status