Returns a crontab with jobs from job path

    It replaces jobs previously generated by this function
    It preserves jobs not generated by this function
6903
def generate_crontab(current_crontab, path_to_jobs, path_to_app, unique_id):
    
    set_disable_envar = ''
    if os.environ.get('DISABLE_COLLECTORS') == 'true':
        set_disable_envar = 'DISABLE_COLLECTORS={} '.format(
            os.environ.get('DISABLE_COLLECTORS'))
    job_template = '{schedule} ' \
                   '{set_disable_envar}' \
                   '{app_path}/venv/bin/pp-collector ' \
                   '-l {collector_slug} ' \
                   '-c {app_path}/config/{credentials} ' \
                   '-t {app_path}/config/{token} ' \
                   '-b {app_path}/config/{performanceplatform} ' \
                   '>> {app_path}/log/out.log 2>> {app_path}/log/error.log'

    crontab = [line.strip() for line in current_crontab]
    crontab = remove_existing_crontab_for_app(crontab, unique_id)
    additional_crontab = []

    job_number = 0
    with open(path_to_jobs) as jobs:
        try:
            for job in jobs:
                parsed = parse_job_line(job)

                if parsed is not None:
                    job_number += 1
                    if skip_job(job_number):
                        continue

                    schedule, collector_slug, credentials, \
                        token, performanceplatform = parsed

                    cronjob = job_template.format(
                        schedule=schedule,
                        set_disable_envar=set_disable_envar,
                        app_path=path_to_app,
                        collector_slug=collector_slug,
                        credentials=credentials,
                        token=token,
                        performanceplatform=performanceplatform
                    )

                    additional_crontab.append(cronjob)

        except ValueError as e:
            raise ParseError(str(e))

    if additional_crontab:
        crontab.append(crontab_begin_comment(unique_id))
        crontab.extend(additional_crontab)
        crontab.append(crontab_end_comment(unique_id))

    return crontab
1077451
def queue_jobs(main_task_path, params_list, queue=None, batch_size=1000):
    
    if len(params_list) == 0:
        return []
    if queue is None:
        task_def = context.get_current_config().get("tasks", {}).get(main_task_path) or {}
        queue = task_def.get("queue", "default")

    from .queue import Queue
    queue_obj = Queue(queue)

    if queue_obj.is_raw:
        raise Exception("Can't queue regular jobs on a raw queue")

    all_ids = []

    for params_group in group_iter(params_list, n=batch_size):

        context.metric("jobs.status.queued", len(params_group))

        # Insert the job in MongoDB
        job_ids = Job.insert([{
            "path": main_task_path,
            "params": params,
            "queue": queue,
            "datequeued": datetime.datetime.utcnow(),
            "status": "queued"
        } for params in params_group], w=1, return_jobs=False)

        all_ids += job_ids

    queue_obj.notify(len(all_ids))
    set_queues_size({queue: len(all_ids)})

    return all_ids
1260473
def schedule_job(job = nil)
      if can_schedule_job?(job)
        callback = ScheduledJob.config.fast_mode
        in_fast_mode = callback ? callback.call(self) : false

        run_at = in_fast_mode ? Time.now.utc + 1 : time_to_recur(Time.now.utc)

        Delayed::Job.enqueue(new, :run_at => run_at, :queue => queue_name)
      end
    end
1340694
def get_jobs(self, recursive=True):
        
        if recursive:
            ret_dict = self.jobs.copy()
            for link in self._links.values():
                ret_dict.update(link.get_jobs(recursive))
            return ret_dict
        return self.jobs
394371
def UpdateCronJob(self,
                    cronjob_id,
                    last_run_status=db.Database.unchanged,
                    last_run_time=db.Database.unchanged,
                    current_run_id=db.Database.unchanged,
                    state=db.Database.unchanged,
                    forced_run_requested=db.Database.unchanged):
    """"""
    job = self.cronjobs.get(cronjob_id)
    if job is None:
      raise db.UnknownCronJobError("Cron job %s not known." % cronjob_id)

    if last_run_status != db.Database.unchanged:
      job.last_run_status = last_run_status
    if last_run_time != db.Database.unchanged:
      job.last_run_time = last_run_time
    if current_run_id != db.Database.unchanged:
      job.current_run_id = current_run_id
    if state != db.Database.unchanged:
      job.state = state
    if forced_run_requested != db.Database.unchanged:
      job.forced_run_requested = forced_run_requested
1346863
public function listJobs($crontab){

        $process = new Process($this->crontabCommand($crontab).' -l');
        $process->run();

        $this->error = $process->getErrorOutput();
        return $process->getOutput();

    }
1120004
def set_job(user, path, mask, cmd):
    '''
    
    '''
    # Scrub the types
    mask = six.text_type(mask).upper()

    # Check for valid mask types
    for item in mask.split(','):
        if item not in _MASK_TYPES:
            return 'Invalid mask type: {0}' . format(item)

    updated = False
    arg_mask = mask.split(',')
    arg_mask.sort()
    lst = list_tab(user)

    updated_crons = []
    # Look for existing incrons that have cmd, path and at least one of the MASKS
    # remove and replace with the one we're passed
    for item, cron in enumerate(lst['crons']):
        if path == cron['path']:
            if cron['cmd'] == cmd:
                cron_mask = cron['mask'].split(',')
                cron_mask.sort()
                if cron_mask == arg_mask:
                    return 'present'

                if any([x in cron_mask for x in arg_mask]):
                    updated = True
                else:
                    updated_crons.append(cron)
            else:
                updated_crons.append(cron)
        else:
            updated_crons.append(cron)

    cron = {'cmd': cmd, 'path': path, 'mask': mask}
    updated_crons.append(cron)

    lst['crons'] = updated_crons
    comdat = _write_incron_lines(user, _render_tab(lst))
    if comdat['retcode']:
        # Failed to commit, return the error
        return comdat['stderr']

    if updated:
        return 'updated'
    else:
        return 'new'
1098613
private function getNextCronJob(): ?Job
    {
        $cron_id = $this->getNextCronId();

        if (is_null($cron_id)) {
            return null;
        }

        $key = sprintf('%s:%s', self::CRON_QUEUE_NAME, $cron_id);

        $data = json_decode($this->client->get($key), true);

        $this->updateCron($cron_id, $data['cron']);

        $job = $data['job'];

        return new Job($job['class'], $job['queue'], $job['args']);
    }
561367
private void replaceByJobHandle() {
    assert state != JobState.RUNNING : "Running job cannot be replaced.";
    final Job self = this;
    new TAtomic<Job>() {
      @Override public Job atomic(Job old) {
        if( old == null ) return null;
        JobHandle jh = new JobHandle(self);
        jh.start_time = old.start_time;
        return jh;
      }
    }.fork(job_key);
  }
398762
def ReadCronJobs(self, cronjob_ids=None):
    """"""
    if cronjob_ids is None:
      res = [job.Copy() for job in itervalues(self.cronjobs)]

    else:
      res = []
      for job_id in cronjob_ids:
        try:
          res.append(self.cronjobs[job_id].Copy())
        except KeyError:
          raise db.UnknownCronJobError("Cron job with id %s not found." %
                                       job_id)

    for job in res:
      lease = self.cronjob_leases.get(job.cron_job_id)
      if lease:
        job.leased_until, job.leased_by = lease
    return res
1310349
def ReadCronJobRuns(self, job_id, cursor=None):
    """"""
    query = """
    SELECT run, UNIX_TIMESTAMP(write_time)
      FROM cron_job_runs
     WHERE job_id = %s
    """
    cursor.execute(query, [job_id])
    runs = [self._CronJobRunFromRow(row) for row in cursor.fetchall()]
    return sorted(runs, key=lambda run: run.started_at, reverse=True)
1339193
def LeaseCronJobs(self, cronjob_ids=None, lease_time=None):
    """"""
    leased_jobs = []

    now = rdfvalue.RDFDatetime.Now()
    expiration_time = now + lease_time

    for job in itervalues(self.cronjobs):
      if cronjob_ids and job.cron_job_id not in cronjob_ids:
        continue
      existing_lease = self.cronjob_leases.get(job.cron_job_id)
      if existing_lease is None or existing_lease[0] < now:
        self.cronjob_leases[job.cron_job_id] = (expiration_time,
                                                utils.ProcessIdString())
        job = job.Copy()
        job.leased_until, job.leased_by = self.cronjob_leases[job.cron_job_id]
        leased_jobs.append(job)

    return leased_jobs
348851
def requeue(self):
        
        timestamp = str(generate_epoch())
        # get all queue_types and requeue one by one.
        # not recommended to do this entire process
        # in lua as it might take long and block other
        # enqueues and dequeues.
        active_queue_type_list = self._r.smembers(
            '%s:active:queue_type' % self._key_prefix)
        for queue_type in active_queue_type_list:
            # requeue all expired jobs in all queue types.
            keys = [
                self._key_prefix,
                queue_type
            ]

            args = [
                timestamp
            ]
            job_discard_list = self._lua_requeue(keys=keys, args=args)
            # discard the jobs if any
            for job in job_discard_list:
                queue_id, job_id = job.split(':')
                # explicitly finishing a job
                # is nothing but discard.
                self.finish(
                    job_id=job_id,
                    queue_id=queue_id,
                    queue_type=queue_type
                )
1324733
def get_jobs(self, recursive=True):
        
        if recursive:
            ret_dict = self.jobs.copy()
            return ret_dict
        return self.jobs
21040
def job_file(self):
        
        job_file_name = '%s.job' % (self.name)
        job_file_path = os.path.join(self.initial_dir, job_file_name)
        self._job_file = job_file_path
        return self._job_file
1345384
function () {
        const cronJobsToStart = _getNamesOfCronJobsToStart();
        if (!cronJobsToStart && _shouldStartCrons() && Shared.isDbConnectionAvailable() === true) {
            return CronJobManagerJob.startListening().then(function () {
                Logger.tag('Cron').info('Cron Job Manager is started. Starting all available cron jobs');
                return Q();
            }, function (err) {
                Logger.tag('Cron').error('Error starting Cron Job Manager ');
                return Q.reject(err);
            });
        } else if (cronJobsToStart && _shouldStartCrons()) {

            Logger.tag('Cron').info('Starting specific cron jobs "' + cronJobsToStart.join(', ') + '"');

            try {
                const cronJobs = Shared.cronModules(cronJobsToStart);
                let promises = [];
                for (let cron of cronJobs) {
                    // Set force run config
                    cron.forceRun = true;
                    promises.push(cron.worker(cron, cron));
                }
                return Q.all(promises)
                    .then(() => process.exit())
                    .catch(() => process.exit(1));
            } catch (err) {
                process.exit(1);
            }
        } else {
            Logger.tag('Cron').warn('Cron Manager is disabled for this environment.');
            return Q();
        }
    }
798598
def list_current_jobs(self):
        
        jobs = {}
        for job in self.scheduler.get_jobs():
            if job.name not in ('schedule_jobs', 'process_status_queue'):
                jobs[job.name] = job

        return jobs