コード例 #1
0
 def test_find_worker(self):
     db_handler = MagicMock()
     db_handler.find_one.return_value = self.worker.format_for_save()
     self.db_handler.find_one.return_value = self.worker.format()
     self.assertIsInstance(coordinator_flow.find_worker(self.db_handler,
                                                        self.worker_id),
                           Worker)
コード例 #2
0
ファイル: watchlist_flow.py プロジェクト: dmend/meniscus
def process_watchlist_item(db, worker_id):
    """
    process a worker id with respect to the watchlist table.
    delete expired watchlist items
    add or update watchlist entry
    broadcast new worker configuration if watch_count is met
    """

    _delete_expired_watchlist_items(db)

    watch_dict = db.find_one('watchlist', {'worker_id': worker_id})
    if not watch_dict:
        _add_watchlist_item(db, worker_id)
    else:
        # update watchlist entry
        if watch_dict['watch_count'] == WATCHLIST_COUNT_THRESHOLD:
            worker = coordinator_flow.find_worker(db, worker_id)

            if worker.status != 'offline':
                coordinator_flow.update_worker_status(db, worker, 'offline')
                _send_target_list_to_broadcaster(db, worker)

        _update_watchlist_item(db, watch_dict)
コード例 #3
0
 def test_find_worker_empty(self):
     db_handler = MagicMock()
     db_handler.find_one.return_value = None
     with self.assertRaises(falcon.HTTPError):
         coordinator_flow.find_worker(db_handler, self.worker_id)