Exemplo n.º 1
0
  def sliceJob(self):
    #download our slice file
    sliceFile = self.downloadFile(self.data['job']['slicejob']['input_file'])
    
    #create and run our slicer
    g = ginsu.Ginsu(sliceFile, self.data['job']['slicejob'])
    g.slice()
    
    #watch the slicing progress
    localUpdate = 0
    lastUpdate = 0
    while g.isRunning():
      #check for messages like shutdown or stop job.
      self.checkMessages()
      if not self.running or self.data['status'] != 'slicing':
        self.debug("Stopping slice job")
        g.stop()
        return
      
      #notify the local mothership of our status.
      if (time.time() - localUpdate > 0.5):
        self.data['job']['progress'] = g.getProgress()
        self.sendMessage('job_update', self.data['job'])
        localUpdate = time.time()
        
      #occasionally update home base.
      if (time.time() - lastUpdate > 15):
        lastUpdate = time.time()
        self.api.updateJobProgress(self.data['job']['id'], "%0.5f" % g.getProgress())
        
      time.sleep(self.sleepTime)
      
    #how did it go?
    sushi = g.sliceResult
    
    #move the file to the cache directory
    cacheDir = hive.getCacheDirectory()
    baseFilename = os.path.splitext(os.path.basename(self.data['job']['slicejob']['input_file']['name']))[0]
    md5sum = hive.md5sumfile(sushi.output_file)
    uploadFile = "%s%s-%s.gcode" % (cacheDir, md5sum, baseFilename)
    self.debug("Moved slice output to %s" % uploadFile)
    shutil.copy(sushi.output_file, uploadFile)

    #update our slice job progress and pull in our update info.
    self.info("Finished slicing, uploading results to main site.")
    result = self.api.updateSliceJob(job_id=self.data['job']['slicejob']['id'], status=sushi.status, output=sushi.output_log, errors=sushi.error_log, filename=uploadFile)

    #hack because the upload takes forever and mothership probably has an old status.
    self.checkMessages()

    #now pull in our new data.
    self.changeStatus(result['data'])
    
    #notify the queen bee of our status.
    self.sendMessage('job_update', self.data['job'])
Exemplo n.º 2
0
  def sliceJob(self):
    #download our slice file
    sliceFile = self.downloadFile(self.data['job']['slicejob']['input_file'])
    
    #create and run our slicer
    g = ginsu.Ginsu(sliceFile, self.data['job']['slicejob'])
    g.slice()
    
    #watch the slicing progress
    localUpdate = 0
    while g.isRunning():
      #notify the local mothership of our status.
      if (time.time() - localUpdate > 0.5):
        self.data['job']['progress'] = g.getProgress()
        msg = Message('job_update', self.data['job'])
        self.pipe.send(msg)
        localUpdate = time.time()
      time.sleep(0.1)
      
    #how did it go?
    sushi = g.sliceResult
    
    #move the file to the cache directory
    cacheDir = hive.getCacheDirectory()
    baseFilename = os.path.splitext(os.path.basename(self.data['job']['slicejob']['input_file']['name']))[0]
    md5sum = hive.md5sumfile(sushi.output_file)
    uploadFile = "%s%s-%s.gcode" % (cacheDir, md5sum, baseFilename)
    self.debug("Moved slice output to %s" % uploadFile)
    shutil.copy(sushi.output_file, uploadFile)

    #update our slice job progress and pull in our update info.
    self.info("Finished slicing, uploading results to main site.")
    result = self.api.updateSliceJob(job_id=self.data['job']['slicejob']['id'], status=sushi.status, output=sushi.output_log, errors=sushi.error_log, filename=uploadFile)
    self.data = result['data']
    
    #notify the bumblebee of our status.
    msg = Message('slice_update', self.data)
    self.pipe.send(msg)