kopia lustrzana https://github.com/bugout-dev/moonstream
Add jobs endpoint.
rodzic
de39b35f69
commit
6f86ad6a02
|
|
@ -729,3 +729,18 @@ def query_parameter_hash(params: Dict[str, Any]) -> str:
|
|||
).hexdigest()
|
||||
|
||||
return hash
|
||||
|
||||
|
||||
def get_moonworm_jobs(
|
||||
address: str,
|
||||
subscription_type_id: str,
|
||||
entries_limit: int = 100,
|
||||
):
|
||||
entries = get_all_entries_from_search(
|
||||
journal_id=MOONSTREAM_MOONWORM_TASKS_JOURNAL,
|
||||
search_query=f"tag:address:{address} tag:subscription_type:{subscription_type_id}",
|
||||
limit=entries_limit, # load per request
|
||||
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
|
||||
)
|
||||
|
||||
return entries
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from ..actions import (
|
|||
apply_moonworm_tasks,
|
||||
get_entity_subscription_collection_id,
|
||||
EntityCollectionNotFoundException,
|
||||
get_moonworm_jobs,
|
||||
)
|
||||
from ..admin import subscription_types
|
||||
from .. import data
|
||||
|
|
@ -22,7 +23,7 @@ from ..admin import subscription_types
|
|||
from ..middleware import MoonstreamHTTPException
|
||||
from ..reporter import reporter
|
||||
from ..settings import bugout_client as bc, entity_client as ec
|
||||
from ..settings import MOONSTREAM_ADMIN_ACCESS_TOKEN
|
||||
from ..settings import MOONSTREAM_ADMIN_ACCESS_TOKEN, MOONSTREAM_MOONWORM_TASKS_JOURNAL
|
||||
from ..web3_provider import yield_web3_provider
|
||||
|
||||
|
||||
|
|
@ -479,6 +480,59 @@ async def get_subscription_abi_handler(
|
|||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/{subscription_id}/jobs",
|
||||
tags=["subscriptions"],
|
||||
response_model=data.SubdcriptionsAbiResponse,
|
||||
)
|
||||
async def get_subscription_jobs_handler(
|
||||
request: Request,
|
||||
subscription_id: str,
|
||||
) -> Any:
|
||||
token = request.state.token
|
||||
user = request.state.user
|
||||
|
||||
try:
|
||||
collection_id = get_entity_subscription_collection_id(
|
||||
resource_type=BUGOUT_RESOURCE_TYPE_ENTITY_SUBSCRIPTION,
|
||||
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
|
||||
user_id=user.id,
|
||||
)
|
||||
|
||||
# get subscription entity
|
||||
subscription_resource = ec.get_entity(
|
||||
token=token,
|
||||
collection_id=collection_id,
|
||||
entity_id=subscription_id,
|
||||
)
|
||||
|
||||
except EntityCollectionNotFoundException as e:
|
||||
raise MoonstreamHTTPException(
|
||||
status_code=404,
|
||||
detail="User subscriptions collection not found",
|
||||
internal_error=e,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Error get subscriptions for user ({user}) with token ({token}), error: {str(e)}"
|
||||
)
|
||||
raise MoonstreamHTTPException(status_code=500, internal_error=e)
|
||||
|
||||
for field in subscription_resource.required_fields:
|
||||
if "subscription_type_id" in field:
|
||||
subscription_type_id = field["subscription_type_id"]
|
||||
|
||||
if "address" in field:
|
||||
subscription_address = field["address"]
|
||||
|
||||
get_moonworm_jobs_response = get_moonworm_jobs(
|
||||
subscription_type_id=subscription_type_id,
|
||||
address=subscription_address,
|
||||
)
|
||||
|
||||
return get_moonworm_jobs_response
|
||||
|
||||
|
||||
@router.get(
|
||||
"/types", tags=["subscriptions"], response_model=data.SubscriptionTypesListResponse
|
||||
)
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue