Lock Job
@constructor
@ignore
@param {Function} resolve
@param {Function} reject
@param {String?} name
761550
function Job(resolve, reject, name) {
  this.resolve = resolve;
  this.reject = reject;
  this.name = name || null;
}
504558
function Scheduler(config = {})
{
    const stack = []

    let shouldRun = false
    let isRunning = false

    this.addRetryAction = (method, action, config) =>
    {
        action.__method = method

        action.__retry = Object.assign(
            {
                method: method
            },
            defaultRetryConfig,
            config
        )

        return this.addAction(action)
    }

    this.addAction = action =>
    {
        let job = { action }

        let jobPromise = new Promise((resolve, reject) =>
        {
            job.__resolve = resolve
            job.__reject = reject
        })

        stack[action.__method](job)

        if (shouldRun && !isRunning) this.next()

        return jobPromise
    }

    this.push = action =>
    {
        action.__method = PUSH

        return this.addAction(action)
    }

    this.unshift = action =>
    {
        action.__method = UNSHIFT

        return this.addAction(action)
    }

    this.pushRetry = (action, config) =>
    {
        return this.addRetryAction(PUSH, action, config)
    }

    this.unshiftRetry = (action, config) =>
    {
        return this.addRetryAction(UNSHIFT, action, config)
    }

    this.start = () =>
    {
        if (shouldRun) return // avoid running next when already running

        shouldRun = true
        this.next()
    }

    this.pause = () =>
    {
        shouldRun = false
    }

    this.next = () =>
    {
        if (!shouldRun) return isRunning = false

        let job = stack.shift()

        if (!job) return isRunning = false

        isRunning = true

        let executionPromise = this.execute(job)

        if (!config.sync)
        {
            setTimeout(this.next.bind(this), 0)
        }
        else
        {
            executionPromise
            .then(response =>
            {
                this.next()
                return response
            })
        }
    }

    this.execute = job =>
    {
        if (job.action.__retry)
        {
            job.action.__retry.attempts++

            return job.action()
            .then(job.__resolve)
            .catch(error =>
            {
                if (
                    job.action.__retry.limit > 0
                    && job.action.__retry.attempts == job.action.__retry.limit
                )
                {
                    job.__reject(`retry limit reached: ${job.action.__retry.limit}`)
                    return
                }

                // re-schedule job
                this[job.action.__retry.method](job.action)
                .then(job.__resolve)
                .catch(job.__reject)
            })
        }

        return job.action()
        .then(job.__resolve)
        .catch(job.__reject)
    }

    if (config.autostart) this.start()

    return {
        push: this.push,
        unshift: this.unshift,
        pushRetry: this.pushRetry,
        unshiftRetry: this.unshiftRetry,
        start: this.start,
        pause: this.pause,
    }
}
643730
private <T> T doWithLock(LockCallback<T> callback) throws JobPersistenceException {
        return doWithLock(callback, null);
    }
19680
function rejected(reason) {
            var p = new Promise();
            p.then = then;
            states.reject(p, reason);
            return p;

            function then(_, onRejected) {
                try {
                    return resolve(typeof onRejected == 'function' ? onRejected(reason) : rejected(reason));
                } catch (e) {
                    return rejected(e);
                }
            }
        }
311744
function reject(oError, vRequest) {
			if (Array.isArray(vRequest)) {
				vRequest.forEach(reject.bind(null, oError));
			} else {
				vRequest.$reject(oError);
			}
		}
1148945
function doResolve(promise, resolve, reject, value, context) {
  var _reject = reject;
  var then;
  var _resolve;
  try {
    if (value === promise) {
      throw new TypeError('Cannot fulfill promise with itself');
    }
    var isObj = isObject(value);
    if (isObj && value instanceof promise.constructor) {
      adopt(promise, value._state, value._value, value);
    } else if (isObj && (then = value.then) && isFunction(then)) {
      _resolve = function(value) {
        _resolve = _reject = noop;
        doResolve(promise, resolve, reject, value, value);
      };
      _reject = function(reason) {
        _resolve = _reject = noop;
        reject(reason);
      };
      then.call(
        context,
        function(value) { _resolve(value); },
        function(reason) { _reject(reason); }
      );
    } else {
      resolve(value);
    }
  } catch (e) {
    _reject(e);
  }
}
1154488
function reject(promise, reason) {
    if (promise.state !== PENDING) return;

    promise.reason = reason;
    promise.state = REJECTED;

    return resolve(promise);
  }
81482
function scheduleHandler (p1, p2) {
        return setTimeout(function () {
            var x, handler = p1._s ? p2._onFulfilled : p2._onRejected;

            // 2.2.7.3
            // 2.2.7.4
            if (handler === void 0) {
                settlePromise(p2, p1._s, p1._v);
                return;
            }

            try {
                // 2.2.5
                x = handler(p1._v);
            } catch (err) {
                // 2.2.7.2
                settlePromise(p2, $rejected, err);
                return;
            }

            // 2.2.7.1
            settleWithX(p2, x);
        });
    }
132770
protected boolean lockJobIfNeeded() {
    try {
      if (job.isExclusive()) {
        processEngineConfiguration.getCommandExecutor().execute(new LockExclusiveJobCmd(job));
      }

    } catch (Throwable lockException) {
      if (log.isDebugEnabled()) {
        log.debug("Could not lock exclusive job. Unlocking job so it can be acquired again. Catched exception: " + lockException.getMessage());
      }

      // Release the job again so it can be acquired later or by another node
      unacquireJob();
      
      return false;
    }
    
    return true;
  }
1319606
function resolve() {
      var deferred = this,
          clone = deferred.benchmark,
          bench = clone._original;

      if (bench.aborted) {
        // cycle() -> clone cycle/complete event -> compute()'s invoked bench.run() cycle/complete.
        deferred.teardown();
        clone.running = false;
        cycle(deferred);
      }
      else if (++deferred.cycles < clone.count) {
        clone.compiled.call(deferred, context, timer);
      }
      else {
        timer.stop(deferred);
        deferred.teardown();
        delay(clone, function() { cycle(deferred); });
      }
    }
539515
function(name, blockData) {
                var block = blocks.get(name) || defaultBlocks.get(name);
                return Promise(block.applyBlock(blockData, result));
            }
775415
function reject(vReason) {
			vResult = vReason;
			iState = -1;

			if (!bCaught && SyncPromise.listener) {
				SyncPromise.listener(that, false);
			}

			if (fnReject) {
				fnReject(vReason);
				fnReject = fnResolve = null; // be nice to the garbage collector
			}
		}
161716
function drainQueue(jobInfo) {
        function drainNext() {
            return drainQueue;
        }

        var queue = jobInfo.job._queue;

        if (queue.length === 0 && eventQueue.length > 0) {
            queue = jobInfo.job._queue = copyAndClearQueue();
        }

        jobInfo.setPromise(drainOneEvent(queue).then(drainNext, drainNext));
    }
930329
function(name, brk, debugChildren) {
		var deferred = Q.defer();
		var args = process.argv;
		
		grunt.task.clearQueue();
		
		var tasks = args.slice(args.indexOf(name) + 1);
		
		if (debugChildren) {
			tasks.unshift('debug:hook' + (brk ? '-break' : ''));
		}
		
		var child = child_process.fork(
			args[1],
			tasks,
			{
				execArgv: [
					brk
						? '--debug-brk'
						: '--debug'
				]
			}
		);
		
		child.on('exit', function(code) {
			if (code == 0) {
				deferred.resolve();
			}
			else {
				deferred.reject(code);
			}
		});
		
		return deferred.promise;
	}
810477
public synchronized void reject() {
        JingleSession session;
        synchronized (manager) {
            try {
                session = manager.createIncomingJingleSession(this);
                // Acknowledge the IQ reception
                session.setSid(this.getSessionID());
                // session.sendAck(this.getJingle());
                session.updatePacketListener();
                session.terminate("Declined");
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, "Exception in reject", e);
            }
        }
     }
363290
function rejectHandler(err) {
  process.stderr.write(`${err.stack || err}\n`);

  if (sh.config.fatal) {
    sh.exit(1);
  }

  return Promise.reject(err);
}
775385
private void handleLockHeld(String taskId, ShardedJobStateImpl<T> jobState,
      IncrementalTaskState<T> taskState) {
    long currentTime = System.currentTimeMillis();
    int sliceTimeoutMillis = jobState.getSettings().getSliceTimeoutMillis();
    long lockExpiration = taskState.getLockInfo().lockedSince() + sliceTimeoutMillis;
    boolean wasRequestCompleted = wasRequestCompleted(taskState.getLockInfo().getRequestId());

    if (lockExpiration > currentTime && !wasRequestCompleted) {
      // if lock was not expired AND not abandon reschedule in 1 minute.
      long eta = Math.min(lockExpiration, currentTime + 60_000);
      scheduleWorkerTask(null, jobState.getSettings(), taskState, eta);
      log.info("Lock for " + taskId + " is being held. Will retry after " + (eta - currentTime));
    } else {
      ShardRetryState<T> retryState;
      if (wasRequestCompleted) {
        retryState = handleSliceFailure(jobState, taskState, new RuntimeException(
            "Resuming after abandon lock for " + taskId + " on slice: "
                + taskState.getSequenceNumber()), true);
      } else {
        retryState = handleShardFailure(jobState, taskState, new RuntimeException(
          "Lock for " + taskId + " expired on slice: " + taskState.getSequenceNumber()));
      }
      updateTask(jobState, taskState, retryState, false);
    }
  }