示例#1
0
 def execute(self, task=None):
     if task:
         self.task = task
     response = self.fetch()
     self.verify(response)
     self.task.status = "SUCCESS" if self.has_expected_data() else "FAIL"
     self.task.last_run = datetime.now()
     session.commit()
     return self.task
示例#2
0
    def delete_task(self, args):
        try:
            task = session.query(Task).filter_by(id=args.get('id')[0]).first()
            session.delete(task)
            session.commit()
            # still haven't decided on a pattern for this class, as you can see
            return True

        except:
            raise Exception("Could not delete task base on args: %s" % args)
示例#3
0
    def update_task(self, args):
        """
        updates a record. manually and painfully. for now.
        """
        task = yield self.get_task(args["id"])
        # TODO: write a helper in the base class to mimic form.populate_obj()
        # or better yet: make form.populate_obj() work with dicts.
        if 'expected_fields' in args:
            if isinstance(args["expected_fields"], list):
                task.expected_fields = ','.join(str(args['expected_fields']))
            else:
                task.expected_fields = args['expected_fields']
        if 'url' in args:
            task.url = args["url"]
        session.commit()

        raise gen.Return(task)
示例#4
0
    def test_producer_should_load_all_tasks(self):
        responses.add(responses.GET,
                'https://api.github.com',
                body='something',
                status=200)
        responses.add(responses.GET,
                'https://api.github.com/repos/bigodines/api-health/',
                body='mocked',
                status=200)

        t1 = Task(url="https://api.github.com")
        t2 = Task(url="https://api.github.com/repos/bigodines/api-health/")
        session.add(t1)
        session.add(t2)
        session.commit()

        yield cron.producer()
        self.assertEquals(cron.queue.qsize(), 2)
示例#5
0
    def add_task(self, args):
        """
        Stores a new Task() and returns a TaskForm() to be rendered
        or Raise and exception with the invalid/missing fields
        """
        task = Task()
        # TODO: write a helper in the base class to mimic form.populate_obj()
        # or better yet: make form.populate_obj() work with dicts.
        if 'expected_fields' in args:
            if isinstance(args['expected_fields'], list):
                task.expected_fields = ','.join(str(args['expected_fields']))
            else:
                task.expected_fields = args['expected_fields']
        if 'url' in args:
            task.url = args["url"]
        session.add(task)
        session.commit()

        raise gen.Return(task)