Example #1
0
    def check_job(self, job_id):
        try:
            job = get_process_queue().check_job(job_id)
        except ValueError:
            abort(400, 'job_id not valid')

        def ret(status):
            return {'job_status': status, 'job_id': job_id}
        if job is True:
            return ret('DONE')
        if job is False:
            abort(404, 'No such job has ever been spawned')
        else:
            if job.ready():
                try:
                    res = job.get()
                    return res
                except Exception as exc:
                    r = ret('FAILED')
                    r['exception'] = str(exc)
                    return r
            return ret('WIP')
Example #2
0
 def generate(self):
     # prendiamo la rec in causa
     recid = dict(request.POST.allitems())['id']
     rec = self.db._search(_id=recid)[0]
     if rec.filename is not None and os.path.filename.exists(rec.filename):
         return {'status': 'ready',
                 'message': 'The file has already been generated at %s' %
                 rec.filename,
                 'rec': rec
                 }
     rec.filename = 'ror-%s-%s.mp3' % \
                    (rec.starttime.strftime('%y%m%d_%H%M'),
                     filter(lambda c: c.isalpha(), rec.name))
     self.db.update(rec.id, rec.serialize())
     job_id = get_process_queue().submit(
         create_mp3,
         start=rec.starttime,
         end=rec.endtime,
         outfile=os.path.join(get_config()['AUDIO_OUTPUT'], rec.filename))
     print "SUBMITTED: %d" % job_id
     return self.rec_msg("Aggiornamento completato!",
                         job_id=job_id,
                         result='/output/' + rec.filename,
                         rec=rec_sanitize(rec))
Example #3
0
 def running_jobs(self):
     res = {}
     res['last_job_id'] = get_process_queue().last_job_id
     res['running'] = get_process_queue().jobs.keys()
     return res