예제 #1
0
 def test_tasks_run_again(self):
     tasks = self._tasks_for_object('key1')
     task = tasks[5]
     self.assertEquals('run_something_fast', task.method)
     djangotasks.run_task(task)
     with LogCheck(self, _start_message(task)):
         Task.objects._do_schedule()
     self._wait_until('key1', "run_something_fast")
     time.sleep(0.5)
     self._reset('key1', "run_something_fast")
     self._assert_status("successful", task)
     djangotasks.run_task(task)
     output_check = LogCheck(self, fail_if_different=False)
     with output_check:
         Task.objects._do_schedule()
     self._wait_until('key1', "run_something_fast")
     time.sleep(0.5)
     import re
     pks = re.findall(r'(\d+)', output_check.log.getvalue())
     new_task = Task.objects.get(pk=int(pks[0]))
     self.assertEquals(
         _start_message(new_task) + 'INFO: Task ' +
         str(new_task.pk) + ' finished with status "successful"\n',
         output_check.log.getvalue())
     self.assertTrue(new_task.pk != task.pk)
     self.assertEquals("successful", new_task.status)
     tasks = self._tasks_for_object('key1')
     self.assertEquals(new_task.pk, tasks[5].pk)
예제 #2
0
    def test_tasks_run_again(self):
        tasks = self._tasks_for_object("key1")
        task = tasks[5]
        self.assertEquals("run_something_fast", task.method)
        djangotasks.run_task(task)
        with LogCheck(self, _start_message(task)):
            Task.objects._do_schedule()
        self._wait_until("key1", "run_something_fast")
        time.sleep(0.5)
        self._reset("key1", "run_something_fast")
        self._assert_status("successful", task)
        djangotasks.run_task(task)
        output_check = LogCheck(self, fail_if_different=False)
        with output_check:
            Task.objects._do_schedule()
        self._wait_until("key1", "run_something_fast")
        time.sleep(0.5)
        import re

        pks = re.findall(r"(\d+)", output_check.log.getvalue())
        new_task = Task.objects.get(pk=int(pks[0]))
        self.assertEquals(
            _start_message(new_task) + "INFO: Task " + str(new_task.pk) + ' finished with status "successful"\n',
            output_check.log.getvalue(),
        )
        self.assertTrue(new_task.pk != task.pk)
        self.assertEquals("successful", new_task.status)
        tasks = self._tasks_for_object("key1")
        self.assertEquals(new_task.pk, tasks[5].pk)
 def handle(self, *args, **options):
     now = time.time()
     five_minutes_ago = now - 60*2
     hotfolders = Hotfolder.objects.filter(activated=True)
     for folder in hotfolders:
         self.stdout.write('This is folder "%s"\n' % folder.folderName)
         os.chdir(settings.HOTFOLDER_BASE_DIR + folder.folderName)
         for file in os.listdir("."):
             st=os.stat(file)
             mtime=st.st_mtime
             if mtime < five_minutes_ago:
                 if file.endswith(".mov") or file.endswith(".mp4") or file.endswith(".avi") or file.endswith(".ogv") or file.endswith(".m4v") or file.endswith(".mp3") or file.endswith(".ogg"):
                     self.stdout.write('Using file %s\n' % file) 
                     video = Video(title=folder.defaultName,date=datetime.date.today(),description=folder.description,kind=folder.kind,channel=folder.channel,autoPublish=folder.autoPublish)
                     video.save()
                     shutil.copy(settings.HOTFOLDER_BASE_DIR + folder.folderName + '/' + file, settings.HOTFOLDER_MOVE_TO_DIR)
                     video.originalFile = settings.HOTFOLDER_MOVE_TO_DIR + file
                     video.save()
                     os.remove(settings.HOTFOLDER_BASE_DIR + folder.folderName + '/' + file)
                     djangotasks.register_task(video.encode_media, "Encode the files using ffmpeg")
                     encoding_task = djangotasks.task_for_object(video.encode_media)
                     djangotasks.run_task(encoding_task)
                     if settings.USE_BITTORRENT:
                         djangotasks.register_task(video.create_bittorrent, "Create Bittorrent file for video and serve via Bittorrent")
                         torrent_task = djangotasks.task_for_object(video.create_bittorrent)
                         djangotasks.run_task(torrent_task)
예제 #4
0
    def test_tasks_run_required_with_two_required_tasks_successful(self):
        key = 'key3'
        required_task = self._task_for_object(TestModel.run_something_long,
                                              key)
        with_required_task = self._task_for_object(
            TestModel.run_something_with_required, key)
        with_two_required_task = self._task_for_object(
            TestModel.run_something_with_two_required, key)
        task = self._task_for_object(
            TestModel.run_something_with_required_with_two_required, key)
        self.assertEquals("defined", required_task.status)

        djangotasks.run_task(task)

        self._assert_status("scheduled", task)
        self._assert_status("scheduled", with_required_task)
        self._assert_status("scheduled", with_two_required_task)
        self._assert_status("scheduled", required_task)

        self._check_running(key, required_task, None, 'run_something_long_2')
        self._check_running(key, with_required_task, required_task,
                            "run_something_with_required")
        self._check_running(key, with_two_required_task, with_required_task,
                            "run_something_with_two_required")
        self._check_running(key, task, with_two_required_task,
                            "run_something_with_required_with_two_required")

        task = Task.objects.get(pk=task.pk)
        complete_log, _ = DATETIME_REGEX.subn('', task.complete_log())

        self.assertEquals(
            u'Run a successful task started on \n' +
            u'running run_something_long_1\n' +
            u'running run_something_long_2\n' + u'\n' +
            u'Run a successful task finished successfully on \n' +
            u'Run a task with a required task started on \n' +
            u'running run_something_with_required\n' + u'\n' +
            u'Run a task with a required task finished successfully on \n' +
            u'Run a task with two required task started on \n' +
            u'running run_something_with_two_required\n' + u'\n' +
            u'Run a task with two required task finished successfully on \n' +
            u'Run a task with a required task that has a required task started on \n'
            + u'running run_something_with_required_with_two_required\n' +
            u'\n' +
            u'Run a task with a required task that has a required task finished successfully on ',
            complete_log)

        complete_log_direct, _ = DATETIME_REGEX.subn('',
                                                     task.complete_log(True))

        self.assertEquals(
            u'Run a task with two required task started on \n' +
            u'running run_something_with_two_required\n' + u'\n' +
            u'Run a task with two required task finished successfully on \n' +
            u'Run a task with a required task that has a required task started on \n'
            + u'running run_something_with_required_with_two_required\n' +
            u'\n' +
            u'Run a task with a required task that has a required task finished successfully on ',
            complete_log_direct)
예제 #5
0
    def test_tasks_run_check_database(self):
        task = self._task_for_object(TestModel.check_database_settings, "key1")
        djangotasks.run_task(task)
        from django.db import connection

        self._check_running(
            "key1", task, None, "check_database_settings", connection.settings_dict["NAME"] + u"\n"
        )  # May fail if your Django settings define a different test database for each run: in which case you should modify it, to ensure it's always the same.
예제 #6
0
 def test_tasks_run_check_database(self):
     task = self._task_for_object(TestModel.check_database_settings, 'key1')
     djangotasks.run_task(task)
     from django.db import connection
     self._check_running(
         'key1', task, None, 'check_database_settings',
         connection.settings_dict["NAME"] + u'\n'
     )  # May fail if your Django settings define a different test database for each run: in which case you should modify it, to ensure it's always the same.
예제 #7
0
    def test_tasks_run_required_with_two_required_tasks_successful(self):
        key = "key3"
        required_task = self._task_for_object(TestModel.run_something_long, key)
        with_required_task = self._task_for_object(TestModel.run_something_with_required, key)
        with_two_required_task = self._task_for_object(TestModel.run_something_with_two_required, key)
        task = self._task_for_object(TestModel.run_something_with_required_with_two_required, key)
        self.assertEquals("defined", required_task.status)

        djangotasks.run_task(task)

        self._assert_status("scheduled", task)
        self._assert_status("scheduled", with_required_task)
        self._assert_status("scheduled", with_two_required_task)
        self._assert_status("scheduled", required_task)

        self._check_running(key, required_task, None, "run_something_long_2")
        self._check_running(key, with_required_task, required_task, "run_something_with_required")
        self._check_running(key, with_two_required_task, with_required_task, "run_something_with_two_required")
        self._check_running(key, task, with_two_required_task, "run_something_with_required_with_two_required")

        task = Task.objects.get(pk=task.pk)
        complete_log, _ = DATETIME_REGEX.subn("", task.complete_log())

        self.assertEquals(
            u"Run a successful task started on \n"
            + u"running run_something_long_1\n"
            + u"running run_something_long_2\n"
            + u"\n"
            + u"Run a successful task finished successfully on \n"
            + u"Run a task with a required task started on \n"
            + u"running run_something_with_required\n"
            + u"\n"
            + u"Run a task with a required task finished successfully on \n"
            + u"Run a task with two required task started on \n"
            + u"running run_something_with_two_required\n"
            + u"\n"
            + u"Run a task with two required task finished successfully on \n"
            + u"Run a task with a required task that has a required task started on \n"
            + u"running run_something_with_required_with_two_required\n"
            + u"\n"
            + u"Run a task with a required task that has a required task finished successfully on ",
            complete_log,
        )

        complete_log_direct, _ = DATETIME_REGEX.subn("", task.complete_log(True))

        self.assertEquals(
            u"Run a task with two required task started on \n"
            + u"running run_something_with_two_required\n"
            + u"\n"
            + u"Run a task with two required task finished successfully on \n"
            + u"Run a task with a required task that has a required task started on \n"
            + u"running run_something_with_required_with_two_required\n"
            + u"\n"
            + u"Run a task with a required task that has a required task finished successfully on ",
            complete_log_direct,
        )
예제 #8
0
    def test_tasks_run_required_task_failing(self):
        required_task = self._task_for_object(TestModel.run_something_failing, "key1")
        task = self._task_for_object(TestModel.run_something_with_required_failing, "key1")
        self.assertEquals("defined", required_task.status)

        djangotasks.run_task(task)
        self._assert_status("scheduled", task)
        self._assert_status("scheduled", required_task)

        with LogCheck(self, _start_message(required_task)):
            Task.objects._do_schedule()
        time.sleep(0.5)
        self._assert_status("scheduled", task)
        self._assert_status("running", required_task)

        self._wait_until("key1", "run_something_failing")
        time.sleep(0.5)
        self._assert_status("scheduled", task)
        self._assert_status("unsuccessful", required_task)

        with LogCheck(self):
            Task.objects._do_schedule()
        time.sleep(0.5)
        self._assert_status("unsuccessful", task)
        task = Task.objects.get(pk=task.pk)

        complete_log, _ = DATETIME_REGEX.subn("", task.complete_log())
        self.assertTrue(
            complete_log.startswith(
                "Run a failing task started on \nrunning run_something_failing\nTraceback (most recent call last):"
            )
        )
        self.assertTrue(
            complete_log.endswith(
                u', in run_something_failing\n    raise Exception("Failed !")\nException: Failed !\n\n'
                + u"Run a failing task failed on \n"
                + u"Run a task with a required task that fails started\n"
                + u"Run a task with a required task that fails failed"
            )
        )
        complete_log_direct, _ = DATETIME_REGEX.subn("", task.complete_log(True))
        self.assertTrue(
            complete_log_direct.startswith(
                "Run a failing task started on \nrunning run_something_failing\nTraceback (most recent call last):"
            )
        )
        self.assertTrue(
            complete_log_direct.endswith(
                u', in run_something_failing\n    raise Exception("Failed !")\nException: Failed !\n\n'
                + u"Run a failing task failed on \n"
                + u"Run a task with a required task that fails started\n"
                + u"Run a task with a required task that fails failed"
            )
        )
        self.assertEquals("unsuccessful", task.status)
예제 #9
0
 def test_tasks_exception_in_thread(self):
     task = self._task_for_object(TestModel.run_something_long, "key1")
     djangotasks.run_task(task)
     task = self._task_for_object(TestModel.run_something_long, "key1")
     task_delete = self._task_for_object(TestModel.run_something_long, "key1")
     task_delete.delete()
     try:
         Task.objects.get(pk=task.pk)
         self.fail("Should throw an exception")
     except Exception, e:
         self.assertEquals("Task matching query does not exist.", str(e))
예제 #10
0
 def test_tasks_exception_in_thread(self):
     task = self._task_for_object(TestModel.run_something_long, 'key1')
     djangotasks.run_task(task)
     task = self._task_for_object(TestModel.run_something_long, 'key1')
     task_delete = self._task_for_object(TestModel.run_something_long,
                                         'key1')
     task_delete.delete()
     try:
         Task.objects.get(pk=task.pk)
         self.fail("Should throw an exception")
     except Exception, e:
         self.assertEquals("Task matching query does not exist.", str(e))
예제 #11
0
 def test_tasks_run_failing(self):
     task = self._task_for_object(TestModel.run_something_failing, 'key1')
     djangotasks.run_task(task)
     with LogCheck(self, _start_message(task)):
         Task.objects._do_schedule()
     self._wait_until('key1', "run_something_failing")
     time.sleep(0.5)
     new_task = Task.objects.get(pk=task.pk)
     self.assertEquals("unsuccessful", new_task.status)
     self.assertTrue(u'running run_something_failing' in new_task.log)
     self.assertTrue(u'raise Exception("Failed !")' in new_task.log)
     self.assertTrue(u'Exception: Failed !' in new_task.log)
예제 #12
0
 def test_tasks_run_failing(self):
     task = self._task_for_object(TestModel.run_something_failing, "key1")
     djangotasks.run_task(task)
     with LogCheck(self, _start_message(task)):
         Task.objects._do_schedule()
     self._wait_until("key1", "run_something_failing")
     time.sleep(0.5)
     new_task = Task.objects.get(pk=task.pk)
     self.assertEquals("unsuccessful", new_task.status)
     self.assertTrue(u"running run_something_failing" in new_task.log)
     self.assertTrue(u'raise Exception("Failed !")' in new_task.log)
     self.assertTrue(u"Exception: Failed !" in new_task.log)
예제 #13
0
    def test_tasks_run_required_task_failing(self):
        required_task = self._task_for_object(TestModel.run_something_failing,
                                              'key1')
        task = self._task_for_object(
            TestModel.run_something_with_required_failing, 'key1')
        self.assertEquals("defined", required_task.status)

        djangotasks.run_task(task)
        self._assert_status("scheduled", task)
        self._assert_status("scheduled", required_task)

        with LogCheck(self, _start_message(required_task)):
            Task.objects._do_schedule()
        time.sleep(0.5)
        self._assert_status("scheduled", task)
        self._assert_status("running", required_task)

        self._wait_until('key1', 'run_something_failing')
        time.sleep(0.5)
        self._assert_status("scheduled", task)
        self._assert_status("unsuccessful", required_task)

        with LogCheck(self):
            Task.objects._do_schedule()
        time.sleep(0.5)
        self._assert_status("unsuccessful", task)
        task = Task.objects.get(pk=task.pk)

        complete_log, _ = DATETIME_REGEX.subn('', task.complete_log())
        self.assertTrue(
            complete_log.startswith(
                'Run a failing task started on \nrunning run_something_failing\nTraceback (most recent call last):'
            ))
        self.assertTrue(
            complete_log.endswith(
                u', in run_something_failing\n    raise Exception("Failed !")\nException: Failed !\n\n'
                + u'Run a failing task failed on \n' +
                u'Run a task with a required task that fails started\n' +
                u'Run a task with a required task that fails failed'))
        complete_log_direct, _ = DATETIME_REGEX.subn('',
                                                     task.complete_log(True))
        self.assertTrue(
            complete_log_direct.startswith(
                'Run a failing task started on \nrunning run_something_failing\nTraceback (most recent call last):'
            ))
        self.assertTrue(
            complete_log_direct.endswith(
                u', in run_something_failing\n    raise Exception("Failed !")\nException: Failed !\n\n'
                + u'Run a failing task failed on \n' +
                u'Run a task with a required task that fails started\n' +
                u'Run a task with a required task that fails failed'))
        self.assertEquals("unsuccessful", task.status)
예제 #14
0
 def test_tasks_run_cancel_scheduled(self):
     task = self._task_for_object(TestModel.run_something_long, 'key1')
     with LogCheck(self):
         Task.objects._do_schedule()
     djangotasks.run_task(task)
     djangotasks.cancel_task(task)
     with LogCheck(
             self, "INFO: Cancelling task " + str(task.pk) +
             "...\nINFO: Task " + str(task.pk) +
             " finished with status \"cancelled\"\nINFO: ...Task " +
             str(task.pk) + " cancelled.\n"):
         Task.objects._do_schedule()
     new_task = Task.objects.get(pk=task.pk)
     self.assertEquals("cancelled", new_task.status)
     self.assertEquals("", new_task.log)
예제 #15
0
 def handle(self, *args, **options):
     now = time.time()
     five_minutes_ago = now - 60 * 2
     hotfolders = Hotfolder.objects.filter(activated=True)
     for folder in hotfolders:
         self.stdout.write('This is folder "%s"\n' % folder.folderName)
         os.chdir(settings.HOTFOLDER_BASE_DIR + folder.folderName)
         for file in os.listdir("."):
             st = os.stat(file)
             mtime = st.st_mtime
             if mtime < five_minutes_ago:
                 if file.endswith(".mov") or file.endswith(
                         ".mp4") or file.endswith(".avi") or file.endswith(
                             ".ogv") or file.endswith(
                                 ".m4v") or file.endswith(
                                     ".mp3") or file.endswith(".ogg"):
                     self.stdout.write('Using file %s\n' % file)
                     video = Video(title=folder.defaultName,
                                   date=datetime.date.today(),
                                   description=folder.description,
                                   kind=folder.kind,
                                   channel=folder.channel,
                                   autoPublish=folder.autoPublish)
                     video.save()
                     shutil.copy(
                         settings.HOTFOLDER_BASE_DIR + folder.folderName +
                         '/' + file, settings.HOTFOLDER_MOVE_TO_DIR)
                     video.originalFile = settings.HOTFOLDER_MOVE_TO_DIR + file
                     video.save()
                     os.remove(settings.HOTFOLDER_BASE_DIR +
                               folder.folderName + '/' + file)
                     djangotasks.register_task(
                         video.encode_media,
                         "Encode the files using ffmpeg")
                     encoding_task = djangotasks.task_for_object(
                         video.encode_media)
                     djangotasks.run_task(encoding_task)
                     if settings.USE_BITTORRENT:
                         djangotasks.register_task(
                             video.create_bittorrent,
                             "Create Bittorrent file for video and serve via Bittorrent"
                         )
                         torrent_task = djangotasks.task_for_object(
                             video.create_bittorrent)
                         djangotasks.run_task(torrent_task)
예제 #16
0
    def test_send_signal_on_task_completed(self):
        from djangotasks.models import TaskManager
        from djangotasks.signals import task_completed

        def receiver(sender, **kwargs):
            task = kwargs["task"]
            self.assertEqual(TaskManager, sender.__class__)
            self.assertEqual(Task, task.__class__)
            self.assertEqual(TestModel, kwargs["object"].__class__)
            self.assertEqual("successful", task.status)
            # Ensure that this function was called by the Signal
            task.log = "Text added from the signal receiver"
            task.save()

        task_completed.connect(receiver)
        task = self._task_for_object(TestModel.run_something_fast, "key1")
        djangotasks.run_task(task)
        self._check_running("key1", task, None, "run_something_fast", u"Text added from the signal receiver")
        task_completed.disconnect()
예제 #17
0
    def test_send_signal_on_task_completed(self):
        from djangotasks.models import TaskManager
        from djangotasks.signals import task_completed

        def receiver(sender, **kwargs):
            task = kwargs['task']
            self.assertEqual(TaskManager, sender.__class__)
            self.assertEqual(Task, task.__class__)
            self.assertEqual(TestModel, kwargs['object'].__class__)
            self.assertEqual('successful', task.status)
            # Ensure that this function was called by the Signal
            task.log = "Text added from the signal receiver"
            task.save()

        task_completed.connect(receiver)
        task = self._task_for_object(TestModel.run_something_fast, 'key1')
        djangotasks.run_task(task)
        self._check_running('key1', task, None, 'run_something_fast',
                            u'Text added from the signal receiver')
        task_completed.disconnect()
예제 #18
0
 def test_tasks_run_cancel_scheduled(self):
     task = self._task_for_object(TestModel.run_something_long, "key1")
     with LogCheck(self):
         Task.objects._do_schedule()
     djangotasks.run_task(task)
     djangotasks.cancel_task(task)
     with LogCheck(
         self,
         "INFO: Cancelling task "
         + str(task.pk)
         + "...\nINFO: Task "
         + str(task.pk)
         + ' finished with status "cancelled"\nINFO: ...Task '
         + str(task.pk)
         + " cancelled.\n",
     ):
         Task.objects._do_schedule()
     new_task = Task.objects.get(pk=task.pk)
     self.assertEquals("cancelled", new_task.status)
     self.assertEquals("", new_task.log)
예제 #19
0
    def test_tasks_run_cancel_running(self):
        task = self._task_for_object(TestModel.run_something_long, "key1")
        djangotasks.run_task(task)
        with LogCheck(self, _start_message(task)):
            Task.objects._do_schedule()
        self._wait_until("key1", "run_something_long_1")
        djangotasks.cancel_task(task)
        output_check = LogCheck(self, fail_if_different=False)
        with output_check:
            Task.objects._do_schedule()
            time.sleep(0.3)
        self.assertTrue(("Cancelling task " + str(task.pk) + "...") in output_check.log.getvalue())
        self.assertTrue("cancelled.\n" in output_check.log.getvalue())
        # self.assertTrue('INFO: failed to mark tasked as finished, from status "running" to "unsuccessful" for task 3. May have been finished in a different thread already.\n'
        #                in output_check.log.getvalue())

        new_task = Task.objects.get(pk=task.pk)
        self.assertEquals("cancelled", new_task.status)
        self.assertTrue(u"running run_something_long_1" in new_task.log)
        self.assertFalse(u"running run_something_long_2" in new_task.log)
        self.assertFalse("finished" in new_task.log)
예제 #20
0
    def test_tasks_run_cancel_running(self):
        task = self._task_for_object(TestModel.run_something_long, 'key1')
        djangotasks.run_task(task)
        with LogCheck(self, _start_message(task)):
            Task.objects._do_schedule()
        self._wait_until('key1', "run_something_long_1")
        djangotasks.cancel_task(task)
        output_check = LogCheck(self, fail_if_different=False)
        with output_check:
            Task.objects._do_schedule()
            time.sleep(0.3)
        self.assertTrue(("Cancelling task " + str(task.pk) +
                         "...") in output_check.log.getvalue())
        self.assertTrue("cancelled.\n" in output_check.log.getvalue())
        #self.assertTrue('INFO: failed to mark tasked as finished, from status "running" to "unsuccessful" for task 3. May have been finished in a different thread already.\n'
        #                in output_check.log.getvalue())

        new_task = Task.objects.get(pk=task.pk)
        self.assertEquals("cancelled", new_task.status)
        self.assertTrue(u'running run_something_long_1' in new_task.log)
        self.assertFalse(u'running run_something_long_2' in new_task.log)
        self.assertFalse('finished' in new_task.log)
예제 #21
0
    def test_tasks_archive_task(self):
        tasks = self._tasks_for_object("key3")
        task = tasks[0]
        self.assertTrue(task.pk)
        task.status = "successful"
        task.save()
        self.assertEquals(False, task.archived)
        new_task = djangotasks.run_task(task)

        self.assertTrue(new_task.pk)
        self.assertTrue(task.pk != new_task.pk)
        old_task = Task.objects.get(pk=task.pk)
        self.assertEquals(True, old_task.archived, "Task should have been archived once a new one has been created")
예제 #22
0
    def test_tasks_archive_task(self):
        tasks = self._tasks_for_object('key3')
        task = tasks[0]
        self.assertTrue(task.pk)
        task.status = 'successful'
        task.save()
        self.assertEquals(False, task.archived)
        new_task = djangotasks.run_task(task)

        self.assertTrue(new_task.pk)
        self.assertTrue(task.pk != new_task.pk)
        old_task = Task.objects.get(pk=task.pk)
        self.assertEquals(
            True, old_task.archived,
            "Task should have been archived once a new one has been created")
예제 #23
0
    def test_run_task_function(self):
        task = djangotasks.task_for_function(_test_function)
        task = djangotasks.run_task(task)
        self.assertEquals("scheduled", task.status)
        with LogCheck(self, _start_message(task)):
            Task.objects._do_schedule()
        i = 0
        while i < 100:  # 20 seconds should be enough
            i += 1
            time.sleep(0.2)
            task = Task.objects.get(pk=task.pk)
            if task.status == "successful":
                break

        self.assertEquals("successful", task.status)
        self.assertEquals("running _test_function\n", task.log)
예제 #24
0
    def test_run_task_function(self):
        task = djangotasks.task_for_function(_test_function)
        task = djangotasks.run_task(task)
        self.assertEquals("scheduled", task.status)
        with LogCheck(self, _start_message(task)):
            Task.objects._do_schedule()
        i = 0
        while i < 100:  # 20 seconds should be enough
            i += 1
            time.sleep(0.2)
            task = Task.objects.get(pk=task.pk)
            if task.status == "successful":
                break

        self.assertEquals("successful", task.status)
        self.assertEquals("running _test_function\n", task.log)
예제 #25
0
파일: views.py 프로젝트: x3m444/OwnTube
def submit(request):
    ''' The view for uploading the videos. Only authenticated users can upload videos!
    If we use transloadit to encode the videos we use the more or less official python
    "API" to ask transloadit to transcode our files otherwise we use django tasks to make
    a new task task for encoding this video. If we use bittorrent to distribute our files
    we also use django tasks to make the .torrent files (this can take a few minutes for
    very large files '''
    if request.user.is_authenticated():
        if request.method == 'POST':
            form = VideoForm(request.POST, request.FILES or None)
            if form.is_valid():
                cmodel = form.save()
                if cmodel.originalFile:
                    if settings.USE_TRANLOADIT:
                        client = Client(settings.TRANSLOAD_AUTH_KEY,
                                        settings.TRANSLOAD_AUTH_SECRET)
                        params = None
                        if (cmodel.kind == 0):
                            params = {
                                'steps': {
                                    ':original': {
                                        'robot': '/http/import',
                                        'url': cmodel.originalFile.url,
                                    }
                                },
                                'template_id':
                                settings.TRANSLOAD_TEMPLATE_VIDEO_ID,
                                'notify_url': settings.TRANSLOAD_NOTIFY_URL
                            }
                        if (cmodel.kind == 1):
                            params = {
                                'steps': {
                                    ':original': {
                                        'robot': '/http/import',
                                        'url': cmodel.originalFile.url,
                                    }
                                },
                                'template_id':
                                settings.TRANSLOAD_TEMPLATE_AUDIO_ID,
                                'notify_url': settings.TRANSLOAD_NOTIFY_URL
                            }
                        if (cmodel.kind == 2):
                            params = {
                                'steps': {
                                    ':original': {
                                        'robot': '/http/import',
                                        'url': cmodel.originalFile.url,
                                    }
                                },
                                'template_id':
                                settings.TRANSLOAD_TEMPLATE_VIDEO_AUDIO_ID,
                                'notify_url': settings.TRANSLOAD_NOTIFY_URL
                            }
                        result = client.request(**params)
                        cmodel.assemblyid = result['assembly_id']
                        cmodel.published = cmodel.autoPublish
                        cmodel.encodingDone = False
                        cmodel.save()
                    else:
                        cmodel.save()
                        djangotasks.register_task(
                            cmodel.encode_media,
                            "Encode the files using ffmpeg")
                        encoding_task = djangotasks.task_for_object(
                            cmodel.encode_media)
                        djangotasks.run_task(encoding_task)
                if settings.USE_BITTORRENT:
                    djangotasks.register_task(
                        cmodel.create_bittorrent,
                        "Create Bittorrent file for video and serve it")
                    torrent_task = djangotasks.task_for_object(
                        cmodel.create_bittorrent)
                    djangotasks.run_task(torrent_task)
                cmodel.user = request.user
                cmodel.save()
                return redirect(list)

            return render_to_response('videos/submit.html',
                                      {'submit_form': form},
                                      context_instance=RequestContext(request))
        else:
            form = VideoForm()
            return render_to_response('videos/submit.html',
                                      {'submit_form': form},
                                      context_instance=RequestContext(request))
    else:
        return render_to_response('videos/nothing.html',
                                  context_instance=RequestContext(request))
예제 #26
0
 def test_tasks_run_with_space_fast(self):
     task = self._task_for_object(TestModel.run_something_fast, "key with space")
     djangotasks.run_task(task)
     self._check_running("key with space", task, None, "run_something_fast", u"running run_something_fast\n")
예제 #27
0
 def test_tasks_run_successful(self):
     task = self._task_for_object(TestModel.run_something_long, 'key1')
     djangotasks.run_task(task)
     self._check_running(
         'key1', task, None, 'run_something_long_2',
         u'running run_something_long_1\nrunning run_something_long_2\n')
예제 #28
0
def submit(request):
    ''' The view for uploading the videos. Only authenticated users can upload videos!
    If we use transloadit to encode the videos we use the more or less official python
    "API" to ask transloadit to transcode our files otherwise we use django tasks to make
    a new task task for encoding this video. If we use bittorrent to distribute our files
    we also use django tasks to make the .torrent files (this can take a few minutes for
    very large files '''
    if request.user.is_authenticated():
        if request.method == 'POST':
            form = VideoForm(request.POST, request.FILES or None)
            if form.is_valid():
                    cmodel = form.save()
                    if cmodel.originalFile:
                        if settings.USE_TRANLOADIT:
                            client = Client(settings.TRANSLOAD_AUTH_KEY, settings.TRANSLOAD_AUTH_SECRET)
                            params = None
                            if (cmodel.kind==0):
                                params = {
                                    'steps': {
                                        ':original': {
                                            'robot': '/http/import',
                                            'url': cmodel.originalFile.url,
                                        }
                                    },
                                    'template_id': settings.TRANSLOAD_TEMPLATE_VIDEO_ID,
                                    'notify_url': settings.TRANSLOAD_NOTIFY_URL
                                }
                            if (cmodel.kind==1):
                                params = {
                                    'steps': {
                                        ':original': {
                                            'robot': '/http/import',
                                            'url': cmodel.originalFile.url,
                                        }
                                    },
                                    'template_id': settings.TRANSLOAD_TEMPLATE_AUDIO_ID,
                                    'notify_url': settings.TRANSLOAD_NOTIFY_URL
                                }
                            if (cmodel.kind==2):
                                params = {
                                    'steps': {
                                        ':original': {
                                            'robot': '/http/import',
                                            'url': cmodel.originalFile.url,
                                        }
                                    },
                                    'template_id': settings.TRANSLOAD_TEMPLATE_VIDEO_AUDIO_ID,
                                    'notify_url': settings.TRANSLOAD_NOTIFY_URL
                                }
                            result = client.request(**params)
                            cmodel.assemblyid = result['assembly_id']
                            cmodel.published = cmodel.autoPublish
                            cmodel.encodingDone = False
                            cmodel.save()
                        else:
                            cmodel.save()
                            djangotasks.register_task(cmodel.encode_media, "Encode the files using ffmpeg")
                            encoding_task = djangotasks.task_for_object(cmodel.encode_media)
                            djangotasks.run_task(encoding_task)
                    if settings.USE_BITTORRENT:
                        djangotasks.register_task(cmodel.create_bittorrent, "Create Bittorrent file for video and serve it")
                        torrent_task = djangotasks.task_for_object(cmodel.create_bittorrent)
                        djangotasks.run_task(torrent_task)
                    cmodel.user = request.user
                    cmodel.save()
                    return redirect(list)
    
            return render_to_response('videos/submit.html',
                                    {'submit_form': form},
                                    context_instance=RequestContext(request))
        else:
            form = VideoForm()
            return render_to_response('videos/submit.html',
                                    {'submit_form': form},
                                    context_instance=RequestContext(request))
    else:
        return render_to_response('videos/nothing.html',
                            context_instance=RequestContext(request))
예제 #29
0
파일: admin.py 프로젝트: usgin/usgincsv
 def save_model(self, request, obj, form, change):
     obj.save()
     task = djangotasks.task_for_object(obj.run_conversion)
     djangotasks.run_task(task)
예제 #30
0
 def test_tasks_run_successful(self):
     task = self._task_for_object(TestModel.run_something_long, "key1")
     djangotasks.run_task(task)
     self._check_running(
         "key1", task, None, "run_something_long_2", u"running run_something_long_1\nrunning run_something_long_2\n"
     )
예제 #31
0
파일: admin.py 프로젝트: usgin/usgincsv
 def save_model(self, request, obj, form, change):
     obj.save()
     task = djangotasks.task_for_object(obj.run_conversion)
     djangotasks.run_task(task)
예제 #32
0
 def test_tasks_run_with_space_fast(self):
     task = self._task_for_object(TestModel.run_something_fast,
                                  'key with space')
     djangotasks.run_task(task)
     self._check_running('key with space', task, None, 'run_something_fast',
                         u'running run_something_fast\n')