Switch work_request to return bool indicating success

pull/12/head
Guillermo Rodriguez 2023-07-22 19:37:26 -03:00
parent 929b05a37d
commit 534b39f268
No known key found for this signature in database
GPG Key ID: EC3AB66D5D83B392
4 changed files with 25 additions and 21 deletions

View File

@ -121,7 +121,7 @@ class SkynetDiscordFrontend:
ctx: discord.ext.commands.context.Context | discord.Message,
file_id: str | None = None,
binary_data: str = ''
):
) -> bool:
send = ctx.channel.send
if params['seed'] == None:
@ -168,7 +168,7 @@ class SkynetDiscordFrontend:
await self.bot.channel.send(
status_msg,
'skynet has suffered an internal error trying to fill this request')
return
return False
enqueue_tx_id = res['transaction_id']
enqueue_tx_link = f'[**Your request on Skynet Explorer**](https://explorer.{DEFAULT_DOMAIN}/v2/explore/transaction/{enqueue_tx_id})'
@ -222,7 +222,6 @@ class SkynetDiscordFrontend:
await asyncio.sleep(1)
if not ipfs_hash:
timeout_text = f'\n[{timestamp_pretty()}] **timeout processing request**'
embed = discord.Embed(
title='live updates',
@ -230,7 +229,7 @@ class SkynetDiscordFrontend:
color=discord.Color.blue())
await message.edit(embed=embed)
return
return False
tx_link = f'[**Your result on Skynet Explorer**](https://explorer.{DEFAULT_DOMAIN}/v2/explore/transaction/{tx_hash})'
@ -254,6 +253,8 @@ class SkynetDiscordFrontend:
logging.error(f'couldn\'t get ipfs hosted image at {ipfs_link}!')
embed.add_field(name='Error', value=f'couldn\'t get ipfs hosted image [**here**]({ipfs_link})!')
await message.edit(embed=embed, view=SkynetView(self))
return False
else:
logging.info(f'success! sending generated image')
await message.delete()
@ -265,3 +266,5 @@ class SkynetDiscordFrontend:
else: # txt2img
embed.set_image(url=ipfs_link)
await send(embed=embed, view=SkynetView(self))
return True

View File

@ -115,9 +115,9 @@ def create_handler_context(frontend: 'SkynetDiscordFrontend'):
await db_call(
'update_user_stats', user.id, 'txt2img', last_prompt=prompt)
ec = await work_request(user, status_msg, 'txt2img', params, ctx)
success = await work_request(user, status_msg, 'txt2img', params, ctx)
if ec == None:
if success:
await db_call('increment_generated', user.id)
@bot.command(name='redo', help='Redo last request')
@ -153,13 +153,13 @@ def create_handler_context(frontend: 'SkynetDiscordFrontend'):
**user_config
}
ec = await work_request(
success = await work_request(
user, status_msg, 'redo', params, ctx,
file_id=file_id,
binary_data=binary
)
if ec == None:
if success:
await db_call('increment_generated', user.id)
@bot.command(name='img2img', help='Responds with an image')
@ -243,17 +243,16 @@ def create_handler_context(frontend: 'SkynetDiscordFrontend'):
last_binary=ipfs_hash
)
ec = await work_request(
sucess = await work_request(
user, status_msg, 'img2img', params, ctx,
file_id=file_id,
binary_data=ipfs_hash
)
if ec == None:
if success:
await db_call('increment_generated', user.id)
# TODO: DELETE BELOW
# user = 'testworker3'
# status_msg = 'status'

View File

@ -118,7 +118,7 @@ class SkynetTelegramFrontend:
params: dict,
file_id: str | None = None,
binary_data: str = ''
):
) -> bool:
if params['seed'] == None:
params['seed'] = random.randint(0, 0xFFFFFFFF)
@ -161,7 +161,7 @@ class SkynetTelegramFrontend:
await self.update_status_message(
status_msg,
'skynet has suffered an internal error trying to fill this request')
return
return False
enqueue_tx_id = res['transaction_id']
enqueue_tx_link = hlink(
@ -223,7 +223,7 @@ class SkynetTelegramFrontend:
f'\n[{timestamp_pretty()}] <b>timeout processing request</b>',
parse_mode='HTML'
)
return
return False
tx_link = hlink(
'Your result on Skynet Explorer',
@ -253,7 +253,7 @@ class SkynetTelegramFrontend:
reply_markup=build_redo_menu(),
parse_mode='HTML'
)
return
return False
png_img = resp.raw
with Image.open(io.BytesIO(resp.raw)) as image:
@ -290,3 +290,5 @@ class SkynetTelegramFrontend:
reply_markup=build_redo_menu(),
parse_mode='HTML'
)
return True

View File

@ -157,9 +157,9 @@ def create_handler_context(frontend: 'SkynetTelegramFrontend'):
await db_call(
'update_user_stats', user.id, 'txt2img', last_prompt=prompt)
ec = await work_request(user, status_msg, 'txt2img', params)
success = await work_request(user, status_msg, 'txt2img', params)
if ec == None:
if success:
await db_call('increment_generated', user.id)
@ -243,13 +243,13 @@ def create_handler_context(frontend: 'SkynetTelegramFrontend'):
last_binary=ipfs_hash
)
ec = await work_request(
success = await work_request(
user, status_msg, 'img2img', params,
file_id=file_id,
binary_data=ipfs_hash
)
if ec == None:
if success:
await db_call('increment_generated', user.id)
@ -307,13 +307,13 @@ def create_handler_context(frontend: 'SkynetTelegramFrontend'):
**user_config
}
ec = await work_request(
success = await work_request(
user, status_msg, 'redo', params,
file_id=file_id,
binary_data=binary
)
if ec == None:
if success:
await db_call('increment_generated', user.id)
# "proxy" handlers just request routers