Beispiel #1
0
    def test_models_get_job(self):
        """ Test if we are able to get a job by the job_id.
        """
        result = self.gen_test_job()

        result = models.get_job_by_id(result.job_id)

        self.assertIsNotNone(result)

        result = models.get_job_by_id(1310841034102310)
        logging.info('result not there: %s' % str(result))
        self.assertIsNone(result)
Beispiel #2
0
    def test_models_get_job(self):
        """ Test if we are able to get a job by the job_id.
        """
        result = self.gen_test_job()

        result = models.get_job_by_id(result.job_id)

        self.assertIsNotNone(result)

        result = models.get_job_by_id(1310841034102310)
        logging.info('result not there: %s' % str(result))
        self.assertIsNone(result)
Beispiel #3
0
    def test_celery_process_task(self):
        """Test the actual celery process by firing it off.

        Requires a celery worker and mongodb to be running. See the shell
        scripts in the celerystalk module. Will expand setup to make the call
        to spin up a celery worker for testing.
        """

        for i in range(100):
            slice_job = create_dummy_job()

            result = SliceBase.write_files(
                slice_job.job_id, self.model_raw, self.config_raw,
                self.model_filename, self.config_filename)

            self.assertTrue(result)

            job = models.get_job_by_id(slice_job.job_id)
            self.assertIsNotNone(job)
            logging.info('starting task tests')
            tasks.process_job.delay(slice_job.job_id, self.slicer, self.version)
Beispiel #4
0
    def test_models_update_job(self):
        """ Tests if we can update properties and persist them.
        """
        test_job = self.gen_test_job()

        self.assertIsNotNone(test_job)

        # Change the config filename
        config = 'new_config.ini'
        test_job.config = config

        # Update the job
        result = models.update_job(test_job)
        self.assertTrue(result)

        # Retrieve the job to ensure that we have what is in the DB
        result = models.get_job_by_id(test_job.job_id)
        self.assertIsNotNone(result)
        self.assertEqual(result.config, unicode(config))

        # Cleanup - remove the item from the db
        result = models.remove_job(result)
        logging.info('remove_result: %s' % str(result))
        self.assertTrue(result)
Beispiel #5
0
    def test_models_update_job(self):
        """ Tests if we can update properties and persist them.
        """
        test_job = self.gen_test_job()

        self.assertIsNotNone(test_job)

        # Change the config filename
        config = 'new_config.ini'
        test_job.config = config

        # Update the job
        result = models.update_job(test_job)
        self.assertTrue(result)

        # Retrieve the job to ensure that we have what is in the DB
        result = models.get_job_by_id(test_job.job_id)
        self.assertIsNotNone(result)
        self.assertEqual(result.config, unicode(config))

        # Cleanup - remove the item from the db
        result = models.remove_job(result)
        logging.info('remove_result: %s' % str(result))
        self.assertTrue(result)
Beispiel #6
0
def process_job(slice_id, slicer_type, slicer_version):
	"""Takes a slice_job and tries to generate gcode based on it.

        Rev 1: This is all local, there are no temp files or POST/GET calls
            because everything will be local. Eventually it will be moved
            so a server could be devoted to just processing tasks so it would
            have to communicate with another server to get stls, configs etc.

        Celery Task that actually kicks off the slicing subprocess when
	it is run. In the future should handle auto-merging the STLS into one
	file. A slice_job is a Slice Object from models and contains all
        required information to run a task.

        Args:
            slice_job: a SliceJob object
            slicer_type: a string, 'slic3r' used by the factory to determine
                which type of slicer to return.
            slicer_version: a string, 'VERSION097' used by the factory to build
                the path to the slicer executable
        Returns:
            True if the stls were sliced and everything was perfect.
            False if there was an error.
	"""

        # Need to get the slice_job from the db.
        if not slice_id:
            return False

        logging.info('trying to slice job %s' % str(slice_id))
        slice_job = models.get_job_by_id(slice_id)

	# If we don't have everything we need bail
	if not slice_job or not slicer_type or not slicer_version:
            return False

        # GET STL and write to temp dir
        # GET config and write to temp dir
        stl_paths, config_path = TaskHelper.get_stl_config_path(slice_job)

        outputs = TaskHelper.generate_output(slice_job)

        # POST that the slicing job has started
        slicer = SlicerFactory.create_slicer(slicer_type, slicer_version)

        for stl_path, output in zip(stl_paths, outputs):
            result = slicer.slice_job(stl_path, config_path, output)

        # POST The status of the result of the job. If it sliced correctly
        # and gcode is availble to download POST SUCCESS status.
        # On Success
        if not result:
            TaskHelper.update_job_state(slice_job, SliceState.FAILED)

        # TaskHelper.post_gcode(output_path)
        TaskHelper.update_job_state(slice_job, SliceState.SUCCESS)
        logging.info('stls_sliced %s' % str(stl_paths))
        # TaskHelper.cleanup_temp(file_paths)

        # Kick off 'Notification' task for this job
        send_results.delay(slice_job, result)
        return True
Beispiel #7
0
def process_job(slice_id, slicer_type, slicer_version):
    """Takes a slice_job and tries to generate gcode based on it.

        Rev 1: This is all local, there are no temp files or POST/GET calls
            because everything will be local. Eventually it will be moved
            so a server could be devoted to just processing tasks so it would
            have to communicate with another server to get stls, configs etc.

        Celery Task that actually kicks off the slicing subprocess when
	it is run. In the future should handle auto-merging the STLS into one
	file. A slice_job is a Slice Object from models and contains all
        required information to run a task.

        Args:
            slice_job: a SliceJob object
            slicer_type: a string, 'slic3r' used by the factory to determine
                which type of slicer to return.
            slicer_version: a string, 'VERSION097' used by the factory to build
                the path to the slicer executable
        Returns:
            True if the stls were sliced and everything was perfect.
            False if there was an error.
	"""

    # Need to get the slice_job from the db.
    if not slice_id:
        return False

    logging.info('trying to slice job %s' % str(slice_id))
    slice_job = models.get_job_by_id(slice_id)

    # If we don't have everything we need bail
    if not slice_job or not slicer_type or not slicer_version:
        return False

# GET STL and write to temp dir
# GET config and write to temp dir
    stl_paths, config_path = TaskHelper.get_stl_config_path(slice_job)

    outputs = TaskHelper.generate_output(slice_job)

    # POST that the slicing job has started
    slicer = SlicerFactory.create_slicer(slicer_type, slicer_version)

    for stl_path, output in zip(stl_paths, outputs):
        result = slicer.slice_job(stl_path, config_path, output)

# POST The status of the result of the job. If it sliced correctly
# and gcode is availble to download POST SUCCESS status.
# On Success
    if not result:
        TaskHelper.update_job_state(slice_job, SliceState.FAILED)

# TaskHelper.post_gcode(output_path)
    TaskHelper.update_job_state(slice_job, SliceState.SUCCESS)
    logging.info('stls_sliced %s' % str(stl_paths))
    # TaskHelper.cleanup_temp(file_paths)

    # Kick off 'Notification' task for this job
    send_results.delay(slice_job, result)
    return True