Skip to content

Commit

Permalink
update webhook management
Browse files Browse the repository at this point in the history
  • Loading branch information
glorenzo972 committed Apr 18, 2024
1 parent 80300b4 commit a3c000e
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tilellm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async def reader(channel: aioredis.client.Redis):

from tilellm.shared import const
webhook = ""
token=""
item = {}
while True:
try:
Expand Down Expand Up @@ -97,7 +98,20 @@ async def reader(channel: aioredis.client.Redis):
)
addtoqueue = await channel.set(f"{item.get('namespace')}/{item.get('id')}", scrape_status_response.model_dump_json(), ex=expiration_in_seconds)
print(f"Inizio {addtoqueue}")
webhook = item.get('webhook',"")
raw_webhook = item.get('webhook',"")
if '?' in raw_webhook:
webhook, raw_token = raw_webhook.split('?')

if raw_token.startswith('token='):
_, token = raw_token.split('=')
else:
webhook=raw_webhook


logger.info(f"webhook: {webhook}, token: {token}")

print(f"webhook: {webhook}, token: {token}")


pc_result = add_pc_item(itemSingle)
#import datetime
Expand All @@ -107,7 +121,7 @@ async def reader(channel: aioredis.client.Redis):
#pc_result["status"] = current_time

# A POST request to the API
logger.info(f"webhook {webhook}")

scrape_status_response = ScrapeStatusResponse(status_message="Indexing finish",
status_code=3
)
Expand All @@ -116,7 +130,7 @@ async def reader(channel: aioredis.client.Redis):
if webhook:
try:
async with aiohttp.ClientSession() as session:
response = await session.post(webhook, json= pc_result.model_dump(exclude_none=True), headers={"Content-Type": "application/json"})
response = await session.post(webhook, json= pc_result.model_dump(exclude_none=True), headers={"Content-Type": "application/json", "X-Auth-Token":token})
except Exception as ewh:
logger.error(ewh)
pass
Expand All @@ -138,7 +152,7 @@ async def reader(channel: aioredis.client.Redis):
if webhook:
res = PineconeIndexingResult(status=400, error=repr(e))
async with aiohttp.ClientSession() as session:
response = await session.post(webhook, json= res.model_dump(exclude_none=True), headers={"Content-Type": "application/json"})
response = await session.post(webhook, json= res.model_dump(exclude_none=True), headers={"Content-Type": "application/json", "X-Auth-Token":token})

logger.error(f"ERRORE {e}, webhook: {webhook}")
traceback.print_exc()
Expand Down

0 comments on commit a3c000e

Please sign in to comment.