def route_task_run(module, fn): try: task.run(module, fn) return flask.Response("ok") except Exception as e: log.exception("Exception while running task.") flask.abort(500, e)
def run_task(source, task_name): print(f'Runnning <{source}.{task_name}>') try: task.run(source, task_name) print(f'Finished runnning <{source}.{task_name}>') except: print(f'Exception while running <{source}.{task_name}>')
def test_manual_retry_task(self): task_id = manual_retry() result = task.run(task_id) self.assertEqual('fail', result) self.assertTrue(task.exists(task_id)) self.assertFalse(task.is_complete(task_id)) result = task.run(task_id) self.assertNotEqual('fail', result) self.assertTrue(task.exists(task_id)) self.assertTrue(task.is_complete(task_id))
def test_object_retry_deleted_object(self): obj = ObjectWithTasks(42) task_id = obj.retry_value() task.run(task_id) self.assertTrue(task.exists(task_id)) self.assertFalse(task.is_complete(task_id)) del obj result = task.run(task_id) self.assertNotEqual('fail', result) self.assertTrue(task.exists(task_id)) self.assertTrue(task.is_complete(task_id)) self.assertEqual(result, 42)
def test_generator_retry_task(self): task_id = generator_retry() rval = task.run(task_id) result = rval.next() self.assertEqual('fail', result) self.assertTrue(task.exists(task_id)) self.assertFalse(task.is_complete(task_id)) rval = task.run(task_id) result = rval.next() self.assertNotEqual('fail', result) self.assertRaises(StopIteration, rval.next) self.assertTrue(task.exists(task_id)) self.assertTrue(task.is_complete(task_id))
def run(self): q = self.__task_queue while self.keep_working: t = None while t is None: try: if not self.keep_working: print "Worker terminating by request" return t = q.get(timeout = GET_TIMEOUT) except Queue.Empty: pass task.run(t, self.__db_name, self.__classifier, RetweetWeightedAggregator()) q.task_done()
def _setup_logic (self): self._timer = Timer () self._tasks = task.TaskGroup () self._game_loop = get_game_loop () self._event_loop = EventLoop ('screenshot', self._tf_window, self._game_loop, None) self._event_loop.signal_event.add (self.on_sfml_event) self._tasks.add (task.repeat (task.run (self._event_loop.loop_once)))
def _setup_logic(self): self._timer = Timer() self._tasks = task.TaskGroup() self._game_loop = get_game_loop() self._event_loop = EventLoop('screenshot', self._tf_window, self._game_loop, None) self._event_loop.signal_event.add(self.on_sfml_event) self._tasks.add(task.repeat(task.run(self._event_loop.loop_once)))
def test_complex_task(self): task_id = complex_task(10) rval = task.run(task_id) self.assertTrue(task.exists(task_id)) self.assertFalse(task.is_complete(task_id)) total = 0 for x in xrange(5): total += rval.next() self.assertTrue(task.exists(task_id)) self.assertFalse(task.is_complete(task_id)) rval = task.run(task_id) for x in xrange(5): total += rval.next() self.assertRaises(StopIteration, rval.next) self.assertTrue(task.exists(task_id)) self.assertTrue(task.is_complete(task_id)) task_id = complex_task(10) rval = task.run(task_id) self.assertEqual(total, sum(list(rval)))
def execution(message): response = None #key = None intent = match_intent(message.lower()) #searching for key intent if intent in taskdict.responses: key = intent response = random.choice(taskdict.responses[key]) #running task task.run(key) #else: #response = None return response #testing #print(execution('what')) #print(execution(" ")) #print(execution("give me notes about wifi")) #input("") #print(match_intent('notes'))
def test_rerun_old_tasks(self): mock_datetime.set_time_override() try: task_id1 = nofail() task.run(task_id1) task_id2 = nofail() task.run(task_id2) mock_datetime.advance_time_seconds(60) task_id3 = nofail() task.run(task_id3) self.assertFalse(task.is_complete(task_id1)) task.run(task_id1) timeout = mock_datetime.utcnow() - datetime.timedelta(seconds=30) num = task.timeout(timeout) self.assertEqual(num, 1) task_id = task.claim() self.assertEqual(task_id, task_id2) self.assertEqual(task.claim(), None) task.run(task_id) self.assertTrue(task.is_complete(task_id2)) self.assertFalse(task.is_complete(task_id3)) finally: mock_datetime.clear_time_override()
def test_ans_2(self): asserting = lambda out_text: self.assertEqual(out_text, ans2) console_test(q2, lambda: run(), asserting)
import subprocess import sys sys.path.insert(0, "../") from tester import Tester t = Tester() ## from task import createReindeer, run, move, rest ## write tests here -- # part 1 reindeer = createReindeer("Tester can fly 1 km/s for 5 seconds, but then must rest for 10 seconds.") t.test("reindeer input parsing", reindeer, ("Tester", 1, 5, 10)) t.test("reindeer runs 20 km in 50 seconds", run(50, reindeer[1:]), 20) movement = move(5, (0, 4), reindeer[1:]) t.test("respect max travel time in movement - move only for one second", movement[0], 1) t.test("respect max travel time in movement - reach end after one second", movement[1], 5) rested = rest(5, (0, 4), reindeer[1:]) # rest for one second t.test("respect max travel time in resting - do not move", rested[0], 0) t.test("respect max travel time in resting - rest for one second only", rested[1], 5) # part 2 ## -- end of tests def askYesNo(question): print(question + " [y/n]") yes = set(['yes','y', 'ye', ''])
def calc_markdown_thumbnail_list(**kwargs): category_filter = kwargs.get('category', 'tech') date_filter = kwargs.get('date', None) label_filter = kwargs.get('label', None) app.logger.debug( 'calc_markdown_thumbnail_list category_filter=%s; date_filter=%s; label_filter=%s' % (category_filter, date_filter, label_filter)) # 检测markdown文件和db上数据是否一致 task.run() data = thumbnail.fetchgroup(category_filter) if data is None or len(data) == 0: return {'outlines': [], 'dates': [], 'labels': []} blog_list = [] dates = set() labels = set() for item in data: # 提取日期 date = item[thumbnail.DATE] split_date = [] if len(date) != 0: split_date = date.replace('/', '-').split('-') if len(split_date) == 3: dates.add(split_date[0] + '-' + split_date[1]) # 提取标签 split_label = item[thumbnail.LABEL].split(',') item_labels_with_url = {} if len(split_label) != 0: for label in split_label: labels.add(label) item_labels_with_url[label] = url_for('show_category_filter', category=category_filter, label=label) if (date_filter is None and label_filter is None) \ or (date_filter is not None and date_filter == '%s-%s' % (split_date[0], split_date[1])) \ or (label_filter is not None and (label_filter in split_label)): # 博客列表内容 title_url = url_for( 'show_%s_markdown' % category_filter, file_path=item[thumbnail.FILE_PATH][len('markdown/%s/' % category_filter):]) blog_list.append({ 'title': item[thumbnail.TITLE], 'title_url': title_url, 'content': item[thumbnail.OUTLINE], 'date': item[thumbnail.DATE], 'labels': item_labels_with_url }) dates_with_url = [] dates = list(dates) dates.sort(reverse=True) for date in dates: split_date = date.split('-') if len(split_date) == 2: new_date = split_date[0] + '年' + split_date[1] + '月' dates_with_url.append((new_date, url_for('show_category_filter', category=category_filter, date=date))) labels_with_url = [] labels = list(labels) labels.sort() for label in labels: labels_with_url.append((label, url_for('show_category_filter', category=category_filter, label=label))) return { 'outlines': blog_list, 'dates': dates_with_url, 'labels': labels_with_url }
def test_change_task_name(self): task_id = one_name() task.run(task_id) self.assertTrue(task.exists(task_id)) self.assertTrue(task.is_complete(task_id)) self.assertEqual(task.get(task_id)['task_name'], 'another_name')
def test_retry_same_kwargs(self): kwargs = {'num': 75, 'str': 'arbitrary', 'dict': {'more': 7.5}} task_id = retry(**kwargs) task.run(task_id) _, ret = task.run(task_id) self.assertEqual(kwargs, ret)
def test_retry_same_args(self): args = (75, 'arbitrary', {'more': 7.5}) task_id = retry(*args) task.run(task_id) ret, _ = task.run(task_id) self.assertEqual(args, ret)
def run(self): print('Starting routine ' + self.title) for task in self.tasks: task.run() print("Time's up for routine " + self.title)
yield progress if progress['phase'] < 2: if random.randint(1, 10) > 5: raise task.Failure(progress) progress['phase'] += 1 yield progress if progress['phase'] < 3: if random.randint(1, 10) > 1: raise task.Failure(progress) progress['phase'] += 1 yield progress task.setup_db('sqlite://') # in memory db task_id = unstable_action() def get_results(results): try: for progress in results: print "Phase %s Complete" % progress['phase'] except task.Failure as ex: print "Phase %s Failed" % (ex.progress['phase'] + 1) while not task.is_complete(task_id): results = task.run(task_id) get_results(results) print "Task Completed"
def run(self): for task in self.__tasks: task.run()
from task import createReindeer, run from part2 import simulateSecondBySecond ## time = int(sys.argv[1]) reindeers = [] with open("in.txt") as file: for line in file: reindeer = createReindeer(line) reindeers += [(reindeer[0], reindeer[1:])] # part 1 bestResult = None for reindeer in reindeers: name = reindeer[0] props = reindeer[1] distance = run(time, props) if bestResult == None or distance > bestResult[1]: bestResult = (name, distance) print("part 1:") print("{} will run {} km in {} s".format(bestResult[0], bestResult[1], time)) # part 2 print("part 2:") winners = simulateSecondBySecond(time, reindeers) for winner in winners: print("{} won scoring race with the score of {}".format(winner["name"], winner["score"])) sys.exit(0)
def test_finish_task(self): task_id = finish() task.run(task_id) self.assertTrue(task.exists(task_id)) self.assertTrue(task.is_complete(task_id))
def on_signal(self, task_id): if task_id in self.__task_list: task = self.__task_list[task_id][0] task.run() else: pass
""" Code for running the Smiley experiment. """ # import some libraries from experiment import Experiment import task import post_task # ---------------- SETUP -------------------- # Make an Experiment object to store the experiment info experiment = Experiment() # ---------------- MAIN PROGRAM -------------------- # Run task task.run(experiment) # Run post-task post_task.run(experiment) # cleanup experiment.close()
progress = progress or {'phase': 0} if progress['phase'] < 1: progress['phase'] += 1 yield progress if progress['phase'] < 2: if random.randint(1, 10) > 5: raise task.Failure(progress) progress['phase'] += 1 yield progress if progress['phase'] < 3: if random.randint(1, 10) > 1: raise task.Failure(progress) progress['phase'] += 1 yield progress task.setup_db('sqlite://') # in memory db task_id = unstable_action() def get_results(results): try: for progress in results: print "Phase %s Complete" % progress['phase'] except task.Failure as ex: print "Phase %s Failed" % (ex.progress['phase'] + 1) while not task.is_complete(task_id): results = task.run(task_id) get_results(results) print "Task Completed"