Skip to content

Commit

Permalink
Fix async submission
Browse files Browse the repository at this point in the history
Signed-off-by: Danny Chiao <[email protected]>
  • Loading branch information
adchia committed Sep 17, 2021
1 parent a6c9cc8 commit fc49dfc
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions sdk/python/feast/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import asyncio
import concurrent.futures
import enum
import logging
import os
Expand All @@ -21,7 +21,7 @@
from functools import wraps
from os.path import expanduser, join
from pathlib import Path
from typing import Dict, List, Optional, Tuple
from typing import List, Optional, Tuple

import requests

Expand All @@ -30,6 +30,8 @@
USAGE_ENDPOINT = "https://usage.feast.dev"
_logger = logging.getLogger(__name__)

executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)


@enum.unique
class UsageEvent(enum.Enum):
Expand Down Expand Up @@ -90,14 +92,11 @@ def usage_id(self) -> Optional[str]:
return os.getenv("FEAST_FORCE_USAGE_UUID")
return self._usage_id

async def _send_request(self, json: Dict):
requests.post(USAGE_ENDPOINT, json=json)

def _send_usage_request(self, json):
try:
task = asyncio.ensure_future(self._send_request(json))
future = executor.submit(requests.post, USAGE_ENDPOINT, json=json)
if self._is_test:
asyncio.wait(task)
concurrent.futures.wait([future])
except Exception as e:
if self._is_test:
raise e
Expand Down

0 comments on commit fc49dfc

Please sign in to comment.