Returns task which performs check every second for reconnection.
@return TimerTask returns timer task which will be invoked after user defined interval and tries reconnect.
511887
private TimerTask getTask(){
        TimerTask checkForRestartTask = new TimerTask() {
            @Override
            public void run() {
                if (lastPongAt == 0) return;

                Date currentDate = new Date();
                long timeInterval = (currentDate.getTime() - lastPongAt);
                if (timeInterval >= 2 * pingInterval) {
                    doReconnect();
                }
            }
        };
        return checkForRestartTask;
    }
864568
public function dequeue()
    {
        // if there is only one queue defined, let's use that
        if(count($this->getQueues()) === 1) {
            return $this->getFirstQueue()->dequeue();
        }

        // default: getting a task using the current task selector strategy
        return $this->selectorStrategy->pickNextTask($this->getQueues());
    }
914252
protected function setTimers()
    {
        if (!$this->exists('session.timer.start')) {
            $start = time();

            $this->set('session.timer.start', $start);
            $this->set('session.timer.last', $start);
            $this->set('session.timer.now', $start);
        }

        $this->set('session.timer.last', $this->get('session.timer.now'));
        $this->set('session.timer.now', time());

        return $this;
    }
1078060
public function run()
    {

        // register the default autoloader
        require SERVER_AUTOLOADER;

        // synchronize the application instance and register the class loaders
        $application = $this->application;
        $application->registerClassLoaders();

        // register the applications annotation registries
        $application->registerAnnotationRegistries();

        // sychronize timer instance
        $timer = $this->timer;

        // we lock the timer for this check, because if a cancel is in progress then we do not want to
        // do the isActive check, but wait for the cancelling transaction to finish one way or another
        $timer->lock();

        try {
            // check if the timer is active
            if ($timer->isActive() === false) {
                // create the actual date
                $now = new \DateTime('now');
                // log an info that the timer is NOT active
                $application->getInitialContext()->getSystemLogger()->info(
                    sprintf(
                        'Timer is not active, skipping this scheduled execution at: %s for %s',
                        $now->format('Y-m-d'),
                        $timer->getId()
                    )
                );

                return; // return without do anything
            }

            // set the current date as the "previous run" of the timer
            $timer->setPreviousRun(new \DateTime());

            // set the next timeout, if one is available
            if ($nextTimeout = $this->calculateNextTimeout($timer)) {
                $timer->setNextTimeout($nextTimeout->format(ScheduleExpression::DATE_FORMAT));
            } else {
                $timer->setNextTimeout(null);
            }

            // change the state to mark it as in timeout method
            $timer->setTimerState(TimerState::IN_TIMEOUT);

            // persist changes
            $timer->getTimerService()->persistTimer($timer, false);

        } catch (\Exception $e) {
            $application->getInitialContext()->getSystemLogger()->error($e->__toString());
        }

        // unlock after timeout recalculation
        $timer->unlock();

        // call timeout method
        $this->callTimeout($timer);
    }
445445
public function getStatus()
    {
        try {
            if (!$this->hasRequestParameter(self::TASK_ID_PARAM)) {
                throw new \common_exception_MissingParameter(self::TASK_ID_PARAM, $this->getRequestURI());
            }

            $data = $this->getTaskLogReturnData(
                $this->getRequestParameter(self::TASK_ID_PARAM),
                CompileDelivery::class
            );
            $children = $this->getStatusesForChildren($this->getRequestParameter(self::TASK_ID_PARAM));
            $data['children'] = $children;
            $this->returnSuccess($data);
        } catch (\Exception $e) {
            $this->returnFailure($e);
        }
    }
808911
@GuardedBy("lock")
  private void scheduleBackoff(final Status status) {
    class EndOfCurrentBackoff implements Runnable {
      @Override
      public void run() {
        try {
          synchronized (lock) {
            reconnectTask = null;
            if (reconnectCanceled) {
              // Even though cancelReconnectTask() will cancel this task, the task may have already
              // started when it's being canceled.
              return;
            }
            channelLogger.log(ChannelLogLevel.INFO, "CONNECTING after backoff");
            gotoNonErrorState(CONNECTING);
            startNewTransport();
          }
        } catch (Throwable t) {
          // TODO(zhangkun): we may consider using SynchronizationContext to schedule the reconnect
          // timer, so that we don't need this catch, since SynchronizationContext would catch it.
          log.log(Level.WARNING, "Exception handling end of backoff", t);
        } finally {
          syncContext.drain();
        }
      }
    }

    gotoState(ConnectivityStateInfo.forTransientFailure(status));
    if (reconnectPolicy == null) {
      reconnectPolicy = backoffPolicyProvider.get();
    }
    long delayNanos =
        reconnectPolicy.nextBackoffNanos() - connectingTimer.elapsed(TimeUnit.NANOSECONDS);
    channelLogger.log(
        ChannelLogLevel.INFO,
        "TRANSIENT_FAILURE ({0}). Will reconnect after {1} ns",
        printShortStatus(status), delayNanos);
    Preconditions.checkState(reconnectTask == null, "previous reconnectTask is not done");
    reconnectCanceled = false;
    reconnectTask = scheduledExecutor.schedule(
        new LogExceptionRunnable(new EndOfCurrentBackoff()),
        delayNanos,
        TimeUnit.NANOSECONDS);
  }
827068
public function get( $reconnectOnFailure = false )
    {
        if( $reconnectOnFailure and !$this->isAlive() ) {
            $this->reset();
        }
        return $this->resource;
    }
1129837
public void doReconnect() {
        if(!tryReconnection) return;

        if(nextReconnectInterval == 0){
            nextReconnectInterval = (int)(2000 * Math.pow(2, count));
        } else {
            nextReconnectInterval = (int)(nextReconnectInterval * Math.pow(2, count));
        }

        if(nextReconnectInterval > maxRetryInterval){
            nextReconnectInterval = maxRetryInterval;
        }
        if(count <= maxRetries) {
            if(canReconnect) {
                count++;
                reconnect(new ArrayList<>(subscribedTokens));
                canReconnect = false;
                canReconnectTimer = new Timer();
                canReconnectTimer.schedule(new TimerTask() {
                    @Override
                    public void run() {
                        canReconnect = true;
                    }
                }, nextReconnectInterval);
            }
        }else if(count > maxRetries) {
            // if number of tries exceeds maximum number of retries then stop timer.
            if(timer != null) {
                timer.cancel();
                timer = null;
            }
        }
    }
122018
public Task getTask()
    {
        if (this.getScreenField() instanceof BasePanel)
            return ((BasePanel)this.getScreenField()).getTask();
        else
            return this.getScreenField().getParentScreen().getTask();
    }
359747
function reset(){
		$tmp = $this->milliseconds();
	 	$this->started = microtime( false );
		$this->stopped = null;
		return $tmp;
	 }
603356
async def wait(self):
        
        while True:
            await self.eio.wait()
            await self.sleep(1)  # give the reconnect task time to start up
            if not self._reconnect_task:
                break
            await self._reconnect_task
            if self.eio.state != 'connected':
                break
1271805
public function retry( $delay = true ) {
		if ( $delay ) {
			return Middleware::retry( $this->newRetryDecider(), $this->getRetryDelay() );
		} else {
			return Middleware::retry( $this->newRetryDecider() );
		}
	}
461935
public function taskSave()
    {
        $taskId = $this->getTaskId();
        $tasks = self::taskFileLoad();
        if (empty($taskId)) {
            $task_ids = array_keys($tasks);
            $this->setTaskId(array_pop($task_ids) + 1);
            $this->setTs(date('Y-m-d H:i:s'));
        }

        $tasks[$this->getTaskId()] = $this;
        return $this->taskFileSave($tasks);
    }
1280838
protected function tick()
    {
        while (!$this->_scheduler->isEmpty()) {
            $scheduler_data       = $this->_scheduler->top();
            $timer_id             = $scheduler_data['data'];
            $next_run_time        = -$scheduler_data['priority'];
            $time_now             = microtime(true);
            $this->_selectTimeout = ($next_run_time - $time_now) * 1000000;
            if ($this->_selectTimeout <= 0) {
                $this->_scheduler->extract();

                if (!isset($this->_eventTimer[$timer_id])) {
                    continue;
                }

                // [func, args, flag, timer_interval]
                $task_data = $this->_eventTimer[$timer_id];
                if ($task_data[2] === self::EV_TIMER) {
                    $next_run_time = $time_now + $task_data[3];
                    $this->_scheduler->insert($timer_id, -$next_run_time);
                }
                call_user_func_array($task_data[0], $task_data[1]);
                if (isset($this->_eventTimer[$timer_id]) && $task_data[2] === self::EV_TIMER_ONCE) {
                    $this->del($timer_id, self::EV_TIMER_ONCE);
                }
                continue;
            }
            return;
        }
        $this->_selectTimeout = 100000000;
    }
151767
public function timeTotal()
    {
        if (!$this->isStarted()) {
            return null;
        }
        if (!$this->isStopped()) {
            return $this->timeCurrent() - $this->timeStart();
        }

        return $this->timeStop() - $this->timeStart();
    }
1064234
public function start(Task $task)
    {
        $task->setStatus(Task::STATUS_STARTED);

        $this->om->persist($task);
        $this->om->flush();

        $this->notify(NotifierInterface::MESSAGE_UPDATE);

        return $task;
    }
604183
private function backOff()
  {
    $delay = $this->getDelay();

    $this->client->getLogger()->debug(
        'Retrying task with backoff',
        array(
            'request' => $this->name,
            'retry' => $this->attempts,
            'backoff_seconds' => $delay
        )
    );

    usleep($delay * 1000000);
  }