Put task to generate a delivery from test uri to the task queue
Test uri has to be set and existing
7886
public function generateDeferred()
    {
        try {
            if (! $this->hasRequestParameter(self::REST_DELIVERY_TEST_ID)) {
                throw new \common_exception_MissingParameter(self::REST_DELIVERY_TEST_ID, $this->getRequestURI());
            }

            $test = $this->getResource($this->getRequestParameter(self::REST_DELIVERY_TEST_ID));
            if (! $test->exists()) {
                throw new \common_exception_NotFound('Unable to find a test associated to the given uri.');
            }

            $deliveryClass = $this->getDeliveryClassByParameters();

            /** @var DeliveryFactory $deliveryFactoryService */
            $deliveryFactoryService = $this->getServiceManager()->get(DeliveryFactory::SERVICE_ID);
            $initialProperties = $deliveryFactoryService->getInitialPropertiesFromRequest($this->getRequest());

            $task = CompileDelivery::createTask($test, $deliveryClass, $initialProperties);

            $result = [
                'reference_id' => $task->getId()
            ];

            /** @var TaskLogInterface $taskLog */
            $taskLog = $this->getServiceManager()->get(TaskLogInterface::SERVICE_ID);

            $report = $taskLog->getReport($task->getId());

            if (!empty($report)) {
                if ($report instanceof \common_report_Report) {
                    //serialize report to array
                    $report = json_decode($report);
                }
                $result['common_report_Report'] = $report;
            }

            return $this->returnSuccess($result);
        } catch (\Exception $e) {
            $this->returnFailure($e);
        }
    }
974529
def gen_tasks(self, urls):
        
        tasks = []
        if isinstance(urls, list):
            for url in urls:
                dat = {
                    'url': url,
                    'name': url.split('/')[-1]
                }
                if not self.overwrite and helper.is_file_ok(dat['name']):
                    self.result['skip'] += 1
                else:
                    tasks.append(dat)
        elif isinstance(urls, dict):
            # {k: v} => k is name, v is url value
            for k, v in urls.items():
                dat = {
                    'url': v,
                    'name': k,
                }
                if not self.overwrite and helper.is_file_ok(dat['name']):
                    self.result['skip'] += 1
                else:
                    tasks.append(dat)
        else:
            raise CrawlerParamsError('urls should be list/dict')
        return tasks
1373186
def run(self):
        
        while True:
            path, params = self.path_queue.get()
            errors = run(path, **params)
            self.result_queue.put(errors)
            self.path_queue.task_done()
350652
def add_task(self, func, *args, **kargs):
        
        self.tasks_queue.put((func, args, kargs))
93101
def add_task(task)
      RRRSpec.redis.rpush(RRRSpec.make_key(key, 'tasks'), task.key)
      RRRSpec.redis.rpush(RRRSpec.make_key(key, 'tasks_left'), task.key)
    end
859861
function setupByCopy() {
    let task_dir;
    let required_tasks;

    try {
        const config = require(path.join(process.cwd(), 'project.config'));
        required_tasks = config.required_tasks;
        if (!required_tasks) {
            throw Error('no task required.');
        }
        task_dir = config.dir.task;
        if (!task_dir) {
            throw Error('task directory not defined.');
        }
    } catch (error) {
        console.warn(error);
        process.exit(0);
    }

    const dstTaskDir = path.join(process.cwd(), task_dir);
    if (!fs.existsSync(dstTaskDir)) {
        // create tasks dir
        fs.mkdirSync(dstTaskDir);
    }

    required_tasks.forEach((task) => {
        const src = path.join(__dirname, 'tasks', task);
        const dst = path.join(dstTaskDir, task);
        if (fs.existsSync(src)) {
            if (fs.existsSync(dst)) {
                fs.unlinkSync(dst);
            }
            fs.writeFileSync(dst, fs.readFileSync(src).toString());
        } else {
            console.error('task not found: ' + task);
            process.exit(1);
        }
    });
}
1109208
def task_path(cls, project, location, queue, task):
        """"""
        return google.api_core.path_template.expand(
            "projects/{project}/locations/{location}/queues/{queue}/tasks/{task}",
            project=project,
            location=location,
            queue=queue,
            task=task,
        )
522650
def _update_task(self, task):
        
        self.task = task
        self.task.data.update(self.task_data)
        self.task_type = task.task_spec.__class__.__name__
        self.spec = task.task_spec
        self.task_name = task.get_name()
        self.activity = getattr(self.spec, 'service_class', '')
        self._set_lane_data()
1082116
async def insert(self, task: Task) -> None:
        ''''''

        if not isinstance(task, Task):
            task = task()

        if task.name not in self.all_tasks:
            task.tasky = self
            self.all_tasks[task.name] = task

            await task.init()

        elif task != self.all_tasks[task.name]:
            raise Exception('Duplicate task %s' % task.name)

        if task.enabled:
            task.task = asyncio.ensure_future(self.start_task(task))
            self.running_tasks.add(task)
        else:
            task.task = None

        return task
564085
public void initialize() {

        if (m_taskFuture != null) {
            // in case initialize has been called before on this object, cancel the existing task
            m_taskFuture.cancel(false);
            m_taskFuture = null;
        }
        m_state = readCompleteConfiguration();
        // In debug mode, use a shorter delay to speed up the test cases
        long delay = DEBUG ? 500 : TASK_DELAY_MILLIS;
        m_taskFuture = OpenCms.getExecutor().scheduleWithFixedDelay(new Runnable() {

            public void run() {

                performUpdate();
            }
        }, delay, delay, TimeUnit.MILLISECONDS);
    }
48688
def put_async(self, path, value):
        "
        request = Put(self._get_next_id(), path, value)
        request.set_callback(self._q.put)
        future = self._dispatch_request(request)
        return future
1088566
def send_task(self, request, response):
        """"""

        # TODO is this too messy?
        from bettercache.tasks import GeneratePage
        try:
            GeneratePage.apply_async((strip_wsgi(request),))
        except:
            logger.error("failed to send celery task")
        self.set_cache(request, response)
992076
def send_task(self, task, force=True):
        '''
        
        '''
        try:
            self.out_queue.put_nowait(task)
        except Queue.Full:
            if force:
                self._send_buffer.appendleft(task)
            else:
                raise
427694
function queueTasks (testTasks, buildTasks) {
      // Queue up test tasks, removing them if already queued up
      _.forEach({ test: testTasks, build: buildTasks }, (queuingTasks, type) => {
        _.forEach(queuingTasks, (task) => {
          // Remove if already queued
          const removed = _.remove(queue[type], (queuedTask) => { return (queuedTask === task); });
          // Queue task ...
          queue[type].push(task);
          // Reorder tasks by original configuration ordering
          queue[type] = _.sortBy(queue[type], (queuedTask) => {
            return _.findIndex(orderedTasks, (originalTask) => {
              return (originalTask === queuedTask);
            });
          });
          // Prompt queued task
          console.log(`> ${removed.length ? 'Requeued' : 'Queued'} ${ type } task for execution: "${ task.blue }"`);
          console.log(`  Queue: ${ [...queue.test, ...queue.build].join(', ').gray }`);
        });
      });
      // Execute tasks from the queue
      executeQueuedTasks();
    }
1220863
def dispatchToUrl(anUri)
      uri = URI.join(anUri, 'tasks/new')
      Net::HTTP.post_form(uri, {'taskName' => self.class.taskName, 'platform' => @platform, 'filename' => @filename})
    end
1056261
function task() {

	// generate commit using default global release environment options
	var commitTask = coopt._getCommitTask();
	var commit = commitTask.commit;

	// register or run the release task (depends on task runner)
	rbot.task(commitTask.commitOpts.pluginName, commitTask.commitOpts.pluginDesc,
			function releaseTask() {
				var options = this.options(commitTask.defaultTaskOptions);
				if (options.gitHostname && commit.username) {
					options.hideTokenRegExp = new RegExp('(' + commit.username + ':)([0-9a-f]+)(@'
							+ options.gitHostname + ')');
				}
				release(this, options);
			});

	/**
	 * When a release commit message is received a release is performed and a
	 * repository web site is published
	 * 
	 * @param task
	 *            the currently running task
	 * @param options
	 *            the task options
	 */
	function release(task, options) {
		var doneAsync = null;

		// validate commit
		if (!commit.versionValidate()) {
			return;
		}
		rbot.log.info('Preparing release: ' + commit.version + ' (last release: '
				+ (commit.prev.versionTag ? commit.prev.versionTag : 'N/A') + ')');
		var useGitHub = options.gitHostname.toLowerCase() === github.hostname;

		var tmpltData = genTemplateData('name', 'pkgCurrVerBumpMsg', 'pkgNextVerBumpMsg', 'distBranchPubMsg');

		var chgLogRtn = '', athrsRtn = '', pubHash = '', distAssets = [];
		var distZipAsset = '', distTarAsset = '', distZipAssetName = '', distTarAssetName = '';
		var pubSrcDir = options.distDir ? path.join(commit.buildDir, options.distDir) : commit.buildDir;
		var pubDistDir = options.distBranch ? commit.buildDir.replace(commit.reponame, options.distBranch) : '';

		// initialize library instances
		var rollCall = new RollCall(options);
		var cmdObj = new Cmd(commit, options, rollCall);
		var cmd = cmdObj.cmd;
		var chkoutRun = cmdObj.chkoutRun;
		var pack = new Pack(commit, options, rollCall, cmdObj);

		// start work
		rollCall.then(remoteSetup).then(pkgUpdate).then(changeLog).then(authorsLog).then(addAndCommitDistDir).then(
				genDistAssets);
		rollCall.then(function() {
			if (useGitHub) {
				doneAsync = task.async();
				rollCall.then(gitHubRelease);
			} else {
				rollCall.then(gitRelease);
			}
		});
		// begin release
		rollCall.start(function(rbcnt) {
			var ecnt = rollCall.errorCount();
			var msg = ecnt > 0 ? 'Processed ' + rbcnt + ' rollback action(s)' : 'Released ' + commit.versionTag;
			rbot.log.info(msg);

			// non-critical cleanup
			try {
				if (ecnt <= 0 && tmpltData.pkgNextVerBumpMsg) {
					// bump to next version
					pkgUpdate(null, null, false, true, true);
				}
			} catch (e) {
				rollCall.error('Failed to bump next release version', e);
			}
			try {
				// update the commit task
				coopt._cloneAndSetCommitTask(commitTask);
			} catch (e) {
				rollCall.error('Failed to set global commit result properties', e);
			}

			// complete
			if (doneAsync) {
				doneAsync(ecnt <= 0);
			} else if (ecnt > 0) {
				throw new Error('Release failed');
			}
		});

		/**
		 * Generates an object that contains each of the passed arguments as a
		 * property with a value of an option with the same name. Each property
		 * will have a value for that option that is parsed using the template
		 * processor.
		 * 
		 * @returns the parsed template data
		 */
		function genTemplateData() {
			var templateData = {
				data : {
					process : process,
					commit : commit,
					env : commitTask.commitOpts,
					options : options
				}
			};
			var rtn = {};
			var arr = Array.prototype.slice.call(arguments, 0);
			arr.forEach(function genIntMsgs(s) {
				rtn[s] = options[s] ? rbot.processTemplate(options[s], templateData) : '';
				if (rtn[s]) {
					rbot.log.verbose(s + ' = ' + rtn[s]);
				}
			});
			return rtn;
		}

		/**
		 * Remote Git setup to permit pushes
		 */
		function remoteSetup() {
			var link = '${GH_TOKEN}@' + options.gitHostname + '/' + commit.slug + '.git';
			cmd('git config --global user.email "' + options.repoEmail + '"');
			cmd('git config --global user.name "' + options.repoUser + '"');
			cmd('git remote rm ' + options.repoName);
			cmd('git remote add ' + options.repoName + ' https://' + commit.username + ':' + link);
		}

		/**
		 * Updates the package file version using the current {Commit} version
		 * and commits/pushes it to remote
		 * 
		 * @param altPkgPath
		 *            the alternative path to the package that will be updated
		 * @param altPkgBowerPath
		 *            the alternative path to the bower package that will be
		 *            updated
		 * @param noPush
		 *            true to only update the package file
		 * @param isNext
		 *            true when the version should be updated to the next
		 *            version versus the default current one
		 * @param noRollback
		 *            true to exclude a rollback for the update
		 */
		function pkgUpdate(altPkgPath, altPkgBowerPath, noPush, isNext, noRollback) {
			chkoutRun(commit.branch, upkg, false, isNext);
			if (!noRollback) {
				rollCall.addRollback(function pkgUpdateRollback() {
					chkoutRun(commit.branch, upkg, true);
				});
			}
			function upkg(revert, next) {
				commit.versionPkg({
					replacer : options.pkgJsonReplacer,
					space : options.pkgJsonSpace,
					revert : revert,
					next : next,
					altWrite : pkgWritable,
					altPkgPath : altPkgPath,
					altPkgPathBower : altPkgBowerPath
				}, pkgPush);
			}
			function pkgWritable(pkgData) {
				pkgLog(pkgData, true);
				return pkgData.pkgStr;
			}
			function pkgPush(pd, pdBower) {
				// TODO : check to make sure there isn't any commits ahead of
				// this one
				if (!noPush && (pd.u || pd.r || pd.n)) {
					cmd('git commit -q -m "' + (pd.r ? 'Rollback: ' : '')
							+ (pd.n ? tmpltData.pkgNextVerBumpMsg : tmpltData.pkgCurrVerBumpMsg) + '" ' + pd.p);
					cmd('git push ' + options.repoName + ' ' + commit.branch);
				}
				pkgLog(pd, false);
				pkgLog(pdBower, false);
			}
			function pkgLog(pd, beforeWrite) {
				if (!pd) {
					return;
				}
				var skip = !pd.n && !pd.r && !pd.u;
				var m = (skip ? 'Skip' : pd.r ? 'Revert' : 'Bump') + (beforeWrite ? 'ing' : (skip ? 'p' : '') + 'ed')
						+ (skip ? ' write:' : pd.n ? ' next' : '') + ' version from ' + pd.oldVer + ' to '
						+ pd.pkg.version + ' in ' + pd.path;
				if (pd.r) {
					rbot.log.verbose(m);
				} else {
					rbot.log.info(m);
				}
			}
		}

		/**
		 * Generates/Writes a change log for the current release using all
		 * messages since last tag/release
		 */
		function changeLog() {
			// Generate change log for release using all messages since last
			// tag/release
			if (!options.chgLog) {
				if (options.chgLogRequired) {
					throw new Error('Invalid "options.chgLog": "' + options.chgLog + '" ("options.chgLogRequired": '
							+ options.chgLogRequired + '"');
				}
				return;
			}
			var chgLogPath = path.join(options.distDir, options.chgLog);
			var lastGitLog = commit.prev && !commit.prev.versionVacant() ? commit.prev.versionTag + '..HEAD' : 'HEAD';
			chgLogRtn = cmd('git --no-pager log ' + lastGitLog + ' --pretty=format:"' + options.chgLogLineFormat
					+ '" > ' + chgLogPath, null, false, chgLogPath, options.chgLogSkipRegExps, '<!-- Commit '
					+ commit.hash + ' -->\n')
					|| '';
			utils.validateFile(chgLogPath, rollCall);
		}

		/**
		 * Generates/Writes an authors log for the current release using all
		 * authors since last tag/release
		 */
		function authorsLog() {
			// Generate list of authors/contributors since last tag/release
			if (!options.authors) {
				if (options.authorsRequired) {
					throw new Error('Invalid "options.authors": "' + options.authors + '" ("options.authorsRequired": '
							+ options.authorsRequired + '"');
				}
				return;
			}
			var athrsPath = path.join(options.distDir, options.authors);
			athrsRtn = cmd('git --no-pager shortlog -sen HEAD > ' + athrsPath, null, false, athrsPath,
					options.authorsSkipLineRegExp)
					|| '';
			utils.validateFile(athrsPath, rollCall);
		}

		/**
		 * Adds/Commits everything in the distribution directory for tracking
		 */
		function addAndCommitDistDir() {
			if (commit.pkgPath && options.distDir && !/^(?:\.|\/)[^\.]/.test(options.distDir)) {
				// need to update the package included in the distribution
				pkgUpdate(path.join(options.distDir, commit.pkgPath), commit.pkgPathBower ? path.join(options.distDir,
						commit.pkgPathBower) : null, true, false);
			}
			if (options.distDir || athrsRtn || chgLogRtn) {
				if (options.distDir) {
					cmd('git add --force ' + options.distDir);
				}
				// Commit changes (needed to generate archive asset)
				cmd('git commit -q -m "' + tmpltData.distBranchPubMsg + '"');
			}
		}

		/**
		 * Generates distribution archive assets (i.e. zip/tar)
		 */
		function genDistAssets() {
			if (!options.distDir) {
				rbot.log.info('Skipping generation of distribution assets (no distDir)');
				return;
			}
			if (!options.distAssetDir) {
				rbot.log.info('Skipping generation of distribution assets (no distAssetDir)');
				return;
			}
			// give taskateers a chance to update branch file contents
			utils.updateFiles(options.distAssetUpdateFiles, options.distAssetUpdateFunction, commit.buildDir,
					rollCall.error);
			// Create distribution assets
			distZipAssetName = commit.reponame + '-' + commit.version + '-dist.zip';
			distZipAsset = genAsset(distZipAssetName, 'zip', true, 'application/zip');
			distTarAssetName = commit.reponame + '-' + commit.version + '-dist.tar.gz';
			distTarAsset = genAsset(distTarAssetName, 'tar.gz', false, 'application/x-compressed');

			/**
			 * Generates an Git archive asset and pushes an object
			 * w/path/name/contentType to the distribution assets {Array}
			 * 
			 * @param name
			 *            the name of the asset file
			 * @param type
			 *            the type/format the asset represents
			 * @param compress
			 *            true to add the compression ratio to the Git command
			 * @param ct
			 *            the Content-Type
			 * @returns the file path to the asset
			 */
			function genAsset(name, type, compress, ct) {
				var a = path.resolve(options.distAssetDir, name);
				cmd('git archive -o "' + a + '" --format=' + type
						+ (compress ? ' -' + options.distAssetCompressRatio : '') + ' HEAD:' + options.distDir);
				if (rbot.log.verboseEnabled) {
					rbot.log.verbose('Created ' + a + ' (size: ' + fs.statSync(a).size + ')');
				}
				distAssets.push({
					path : a,
					name : name,
					contentType : ct
				});
				return a;
			}
		}

		/**
		 * Tags release via standard Git CLI
		 */
		function gitRelease() {
			// Tag release
			rbot.log.info('Tagging release ' + commit.versionTag + ' via ' + options.gitHostname);
			cmd('git tag -f -a ' + commit.versionTag + ' -m "'
					+ (chgLogRtn ? chgLogRtn.replace(coopt.regexLines, '$1 \\') : commit.message) + '"');
			cmd('git push -f ' + options.repoName + ' ' + commit.versionTag);
			commit.releaseId = commit.versionTag;
			// TODO : upload asset?
			rollCall.addRollback(rollbackTag);
			rollCall.then(publish);
		}

		/**
		 * Calls the GitHub Release API to tag release and upload optional
		 * distribution asset
		 */
		function gitHubRelease() {
			rbot.log.info('Releasing ' + commit.versionTag + ' via ' + options.gitHostname);
			// GitHub Release API will not remove the tag when removing a
			// release
			github.releaseAndUploadAsset(distAssets, coopt.regexLines, commit, tmpltData.name, chgLogRtn
					|| commit.message, options, rollCall, rollbackTag, function() {
				rollCall.then(publish);
			});
		}

		/**
		 * Publish repository pages to distribution branch (commit should have a
		 * valid ID)
		 */
		function publish() {
			if (!options.distBranch) {
				rbot.log.info('Skipping publishing from "' + pubSrcDir + '" to ' + pubDistDir + ' (no distBranch)');
				return;
			} else if (!commit.releaseId) {
				rbot.log.info('Skipping publishing from "' + pubSrcDir + '" to "' + pubDistDir + '" in branch "'
						+ options.distBranch + '" (no releaseId/tag)');
				return;
			}
			rbot.log.info('Publishing to branch "' + options.distBranch + '"');
			rbot.log.info('Copying publication directories/files from "' + pubSrcDir + '" to "' + pubDistDir + '"');
			// copy all directories/files over that need to be published
			// so that they are not removed by the following steps
			rbot.log.info(utils.copyRecursiveSync(pubSrcDir, pubDistDir, options.distExcludeDirRegExp,
					options.distExcludeFileRegExp).toString());
			// cmd('cp -r ' + path.join(pubSrcDir, '*') + ' ' + pubDistDir);
			chkoutRun(null, publishRun);
			function publishRun() {
				try {
					cmd('git fetch ' + options.repoName + ' ' + options.distBranch);
					pubHash = cmd('git rev-parse HEAD');
				} catch (e) {
					if (util.isRegExp(options.distBranchCreateRegExp) && options.distBranchCreateRegExp.test(e.message)) {
						cmd('git checkout -q --orphan ' + options.distBranch);
					} else {
						throw e;
					}
				}
				if (pubHash) {
					cmd('git checkout -q --track ' + options.repoName + '/' + options.distBranch);
				}
				cmd('git rm -rfq .');
				cmd('git clean -dfq .');
				rbot.log.info('Copying publication directories/files from "' + pubDistDir + '" to "' + commit.buildDir
						+ '"');
				rbot.log.info(utils.copyRecursiveSync(pubDistDir, commit.buildDir).toString());
				// cmd('cp -r ' + path.join(pubDistDir, '*') + '
				// .');

				// give taskateers a chance to update branch file
				// contents
				utils.updateFiles(options.distBranchUpdateFiles, options.distBranchUpdateFunction, commit.buildDir,
						rollCall.error);

				cmd('git add -A');
				cmd('git commit -q -m "' + tmpltData.distBranchPubMsg + '"');
				cmd('git push -f ' + options.repoName + ' ' + options.distBranch);

				rollCall.addRollback(rollbackPublish);
				rollCall.then(pack.publish);
			}
		}

		/**
		 * Deletes tag using Git CLI
		 */
		function rollbackTag() {
			cmd('git push --delete ' + options.repoName + ' ' + commit.versionTag);
		}

		/**
		 * Reverts published branch
		 */
		function rollbackPublish() {
			try {
				chkoutRun(options.distBranch, function() {
					var cph = cmd('git rev-parse HEAD');
					if (pubHash && pubHash !== cph) {
						cmd('git checkout -qf ' + pubHash);
						cmd('git commit -q -m "Rollback: ' + tmpltData.distBranchPubMsg + '"');
						cmd('git push -f ' + options.repoName + ' ' + options.distBranch);
					} else if (!pubHash) {
						cmd('git push ' + options.repoName + ' --delete ' + options.distBranch);
					} else {
						rbot.log.verbose('Skipping rollback for ' + options.distBranch + ' for hash "' + pubHash
								+ '" (current hash: "' + cph + '")');
					}
				});
			} catch (e) {
				var msg = 'Failed to rollback publish branch changes!';
				rollCall.error(msg, e);
			}
		}
	}
}
1337428
def create_context(self, message_queue, task_id):
        
        parent_data = ParentData(self.parent.kind, self.parent.remote_id)
        path_data = self.local_file.get_path_data()
        params = parent_data, path_data, self.local_file.remote_id
        return UploadContext(self.settings, params, message_queue, task_id)