コード例 #1
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)
    instance_id = await client.start_new(req.route_params["functionName"], None, "json string")

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)
コード例 #2
0
ファイル: __init__.py プロジェクト: kloudkrafts01/kspyder
async def main(mytimer: azure.functions.TimerRequest, starter: str):
    
    try:
        orchestrator_name = "F_orchestrator"
        client = df.DurableOrchestrationClient(starter)

        req_params = {
            'trigger': 'scheduled',
            'source': 'prestashop',
            'last_days': '1',
            'model': None,
            'action': 'full'
        }

        req_body = {
            'status': 'TODO'
        }

        orc_input = {
            'params': req_params,
            'body': req_body
        }

        instance_id = await client.start_new(orchestrator_name, None, req_params)

        logger.info(f"Started orchestration with ID = '{instance_id}'.")


    except Exception as e:

        logger.error("F_prestashop_timer :: {}".format(traceback.print_exc()))
コード例 #3
0
ファイル: __init__.py プロジェクト: AndreasDit/Sonntagsfrage
async def main(mytimer: func.TimerRequest, starter: str) -> None:
    client = df.DurableOrchestrationClient(starter)
    # client = df.DurableClient(starter)
    instance_id = await client.start_new("Fctn_Orchestrator_Preprocess", None,
                                         None)

    logging.info(f"Started orchestration with ID = '{instance_id}'.")
コード例 #4
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    try:
        orchest_name = "functionName"
        client = df.DurableOrchestrationClient(starter)

        called_orchest = req.route_params.get(orchest_name)

        client_input = None
        if req.get_body():
            client_input = req.get_json()
        if req.params:
            client_input = dict(req.params)
        if req.params and req.get_body():
            logging.warn("Do not support query params & body in the same time")

        instance_id = await client.start_new(called_orchest, None,
                                             client_input)

        logging.info(f"Started orchestration with ID = '{instance_id}'.")

        return client.create_check_status_response(req, instance_id)

    except Exception as e:
        str_issue = "Client initialisation Issue: {}".format(e)
        logging.error(str_issue, traceback.format_exc())
        return func.HttpResponse(str_issue, status_code=500)
コード例 #5
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)

    #Get function parameters
    functionName = req.route_params["FunctionName"]
    startTimestamp = req.route_params["StartTimestamp"]
    endTimestamp = req.route_params["EndTimestamp"]

    #Get connection to the database
    db = getDatabaseConnection()
    cursor = db.cursor()

    #Setup settings
    cursor.execute("DELETE FROM Settings")

    query = "INSERT INTO settings(process_name, start_tstamp, end_tstamp) VALUES('%s', '%s', '%s')" % (
        functionName, startTimestamp, endTimestamp)
    cursor.execute(query)

    #Close the connection
    db.commit()
    cursor.close()
    db.close()

    instance_id = await client.start_new(functionName, None, None)

    return client.create_check_status_response(req, instance_id)
コード例 #6
0
async def main(msg: func.ServiceBusMessage, starter: str):
    logging.info("starting analyze_text_handler")
    
    message_body = msg.get_body().decode('utf-8')
    logging.info(f"message body: {message_body}")

    message_details = json.dumps({
        'message_id': msg.message_id,   
        'body': msg.get_body().decode('utf-8'),
        'content_type': msg.content_type,
        # 'expiration_time': msg.expiration_time,
        'label': msg.label,
        'partition_key': msg.partition_key,
        'reply_to': msg.reply_to,
        'reply_to_session_id': msg.reply_to_session_id,
        # 'scheduled_enqueue_time': msg.scheduled_enqueue_time,
        'session_id': msg.session_id,
        'time_to_live': msg.time_to_live,
        'to': msg.to,
        'user_properties': msg.user_properties,
        'metadata' : msg.metadata
    })
    logging.info(message_details)

    # State the orchestration function
    logging.info("starting analyze_text_orchestration")
    client = df.DurableOrchestrationClient(starter)
    instance_id = await client.start_new("analyze_text_orchestration", client_input=message_body)
    logging.info(f"started orchestration with instance id: {instance_id}")

    # How to manage an orchestration instance
    # https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-instance-management?tabs=python
コード例 #7
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)
    instance_id = await client.start_new(
        orchestration_function_name="Orchestrator",
        instance_id=None,
        client_input={
            a:req.params.get(a)
            for a in ['publicationCID','publishedDate']
        }
    )

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    csr = client.create_check_status_response(req, instance_id)
    A = json.loads(csr.get_body())
    logging.info(A.get("statusQueryGetUri"))
    ## Set StatusQueryGetUri value in SQL
    update_row_status(
        publicationCID=req.params.get("publicationCID"),
        publishedDate=req.params.get("publishedDate"),
        uri=A.get("statusQueryGetUri")
    )
    update_row_status(
        publicationCID=req.params.get("publicationCID"),
        publishedDate=req.params.get("publishedDate"),
        status='Starting'
    )
    
    return csr
コード例 #8
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)

    functionName = req.route_params["FunctionName"]
    entriesNum = req.route_params["NumberOfEntries"]

    #SQL database attributes
    server = 'server-kymira.database.windows.net'
    database = 'database-kymira'
    username = '******'
    password = '******'
    driver = '{ODBC Driver 17 for SQL Server}'
    connection = 'DRIVER=' + driver + ';SERVER=' + server + ';PORT=1433;DATABASE=' + database + ';UID=' + username + ';PWD=' + password

    query = "DELETE FROM Settings; INSERT INTO Settings(activity_name, entries_num) VALUES('%s', %d)" % (
        functionName, int(entriesNum))

    with pyodbc.connect(connection) as conn:
        with conn.cursor() as cursor:
            cursor.execute(query)

    instance_id = await client.start_new(functionName, None, None)

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)
コード例 #9
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)
    instance_id = await client.start_new('PetClassificationOrchestrator', None, int(req.route_params["count"]))

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)
コード例 #10
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)
    ## Get inputs
    inputs = {}
    # for a,b in []:
    # inputs[a] = req.params.get(b)
    for f in [
            "rowID",
            "url",
            "name",
            "sport",
            "endpointID",
            "multipleVideoEvent",
            "samplingProportion",
            "audioTranscript",
            'databaseID',
    ]:
        inputs[f] = req.params.get(f)
    ## Start orchestrator
    instance_id = await client.start_new(
        orchestration_function_name="Orchestrator",
        instance_id=None,
        client_input=inputs)

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)
コード例 #11
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)
    instance_id = await client.start_new("DurableFunctionsOrchestrator", None,
                                         None)

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)
コード例 #12
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)
    instance_id = await client.start_new('Fctn_Orchestrator_Pipeline',
                                         client_input={"start": "hallo welt"})

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)
コード例 #13
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)
    num_instances = parse_and_validate_input(req.get_body())

    tasks = map(lambda _: client.start_new("SequentialOrchestrator"),
                range(num_instances))
    await gather(tasks=tasks, max_concurrency=200)
    return ""
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    client = df.DurableOrchestrationClient(starter)
    instance_id = await client.start_new("Orchestration", None, None)

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)
コード例 #15
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)
    num_activities = parse_and_validate_input(req.get_body())
    instance_id = await client.start_new("FanOutFanInOrchestrator", None,
                                         num_activities)

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)
コード例 #16
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)
    payload = json.loads(req.get_body().decode())
    instance_id = await client.start_new(req.route_params["functionName"],
                                         client_input=payload)

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)
コード例 #17
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpRequest:
    client = df.DurableOrchestrationClient(starter)
    args = requestparams(json.load())
    result = await userAccountId(args.userEmail)
    if result.success:
        margs = migrationParams(result.msg, args.userEmail)
        instance_id = await client.start_new(
            req.route_params["orchestrator_function"], margs)
        logging.info(f"Started orchestration with ID = '{instance_id}'.")
        return client.create_check_status_response(req, instance_id)
コード例 #18
0
async def function_handler(message: func.ServiceBusMessage, starter: str):
    for msg in [message]:
        client = df.DurableOrchestrationClient(starter)
        message_body = msg.get_body().decode("utf-8")

        # Log the Service Bus Message as plaintext
        #dictionary
        msg = json.loads(message_body)

        instance_id = await client.start_new('orchestrator', None, json.dumps({ 'moco' : 'A', 'attrib': 'a' }))
        instance_id = await client.start_new('orchestrator', None, json.dumps({ 'moco' : 'B', 'attrib': 'b' }))
コード例 #19
0
async def main(msg: func.QueueMessage, starter: str) -> None:
    logging.info('Python queue trigger function processed a queue item: %s',
                 msg.get_body().decode('utf-8'))

    client = df.DurableOrchestrationClient(starter)

    instance_id = await client.start_new(
        orchestration_function_name="Orchestrator",
        instance_id=None,
        client_input=msg.get_body().decode('utf-8')
    )
コード例 #20
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)

    test = json.dumps({"name": "John", "age": 30})

    instance_id = await client.start_new(req.route_params["functionName"],
                                         None, test)

    logging.info(req.get_body())

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)
コード例 #21
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    user_id = req.params['userid']

    client = df.DurableOrchestrationClient(starter)
    orchestration_input = {
        'user_id': user_id,
        'image_count': int(req.route_params["count"])
    }
    instance_id = await client.start_new('PetClassificationOrchestrator', None,
                                         orchestration_input)

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)
コード例 #22
0
ファイル: __init__.py プロジェクト: Hokutosei/chainHello
async def main(mytimer: func.TimerRequest, starter: str) -> None:
    utc_timestamp = datetime.datetime.utcnow().replace(
        tzinfo=datetime.timezone.utc).isoformat()

    # if mytimer.past_due:
    client = df.DurableOrchestrationClient(starter)
    logging.info('The timer is past due!')
    instance_id = await client.start_new('DurableFunctionsOrchestrator1', None,
                                         None)
    logging.info(
        f"started orchestration with ID = '{instance_id}' at '{utc_timestamp}'"
    )

    logging.info(
        'Python timer trigger function ran at %s DurableOrchestrationContext',
        utc_timestamp)
コード例 #23
0
async def main(myblob: func.InputStream, starter: str):
    client = df.DurableOrchestrationClient(starter)

    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")

    instance_id = await client.start_new(
        "Orchestrator",
        None,
        {
            "path": myblob.name,
            "uri": myblob.uri,
            "length": myblob.length
        },
    )

    logging.info(f"Started orchestration with ID = '{instance_id}'.")
コード例 #24
0
ファイル: __init__.py プロジェクト: kloudkrafts01/kspyder
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    
    try:
        client = df.DurableOrchestrationClient(starter)

        logger.info("request parameters: {}".format(req.params))

        expected_params = [
            'last_days',
            'source',
            'model',
            'action'
        ]

        # req_params = dict(req.params)
        params = {}
        # req_body = req.get_body()
        req_body = {
            'status': 'TODO'
        }

        for key in expected_params:
            params[key] = (req.params[key] if key in req.params.keys() else None)
        
        params['trigger'] = 'http'
        models_raw = params['model']
        params['model'] = (models_raw.split(',') if models_raw else None)

        orc_input = {
            'params': params,
            'body': req_body
        }

        instance_id = await client.start_new(req.route_params["functionName"], None, params)

        logger.info(f"Started orchestration with ID = '{instance_id}'.")

        return client.create_check_status_response(req, instance_id)

    except Exception as e:

        logger.error("F_starter :: {}".format(e))
コード例 #25
0
ファイル: __init__.py プロジェクト: lobokie/AZ-204
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)
    instance_id = await client.start_new(req.route_params["functionName"],
                                         None, None)

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)


# const df = require("durable-functions");

# module.exports = async function (context, req) {
#     const client = df.getClient(context);
#     const instanceId = await client.startNew(req.params.functionName, undefined, req.body);

#     context.log(`Started orchestration with ID = '${instanceId}'.`);

#     return client.createCheckStatusResponse(context.bindingData.req, instanceId);
# };
コード例 #26
0
ファイル: __init__.py プロジェクト: Ngolobe/Data-Engineering
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:

    # try retrieving the body from the request
    try:
        body = json.loads(req.get_body())
    except:
        # no body
        logging.info("No body provided in the request")
        body = {}

    # client for an orchestration
    client = df.DurableOrchestrationClient(starter)
    
    # call the orchestration function provided in the request with the provided body
    instance_id = await client.start_new(req.route_params["functionName"], None, body)

    # the function starts the orchestration process and continues here to log and return instanse ids
    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)
コード例 #27
0
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    ## `req` requires parameters:
    # 'fileUrl',
    # 'imagesAlreadyCreated',
    # 'RowID'
    client = df.DurableOrchestrationClient(starter)
    options = get_options(user='******', req=req)
    logging.info(f"options: {options}")
    instance_id = await client.start_new(
        orchestration_function_name="Orchestrator",
        instance_id=None,
        client_input=options)
    csr = client.create_check_status_response(req, instance_id)
    statusQueryGetUri = json.loads(csr.get_body()).get('statusQueryGetUri')

    update_row_status(rowID=options['RowID'], uri=statusQueryGetUri)
    update_row_status(rowID=options['RowID'],
                      status=f'Starting - {os.getenv("appName")}')

    return client.create_check_status_response(req, instance_id)
コード例 #28
0
async def main(event: func.EventGridEvent, starter: str):
    client = df.DurableOrchestrationClient(starter)
    logging.info("Python EventGrid trigger processed an event: %s",
                 event.get_json())
    blob = Blob(full_url=event.get_json()["url"])
    logging.info(f"Blob: {blob}")
    try:
        status = await client.get_status(blob.order_id)
        instance_id = status.instance_id
        logging.info("Got existing orchestrator, with instance id: %s",
                     instance_id)
    except Exception:
        instance_id = await client.start_new("Orchestrator", blob.order_id,
                                             None)
        logging.info("Started new orchestration, with instance id: %s",
                     instance_id)
    if instance_id:
        await client.raise_event(instance_id, blob.file_type, True)
    else:
        logging.error("Could not start orchestrator for instance: %s",
                      blob.order_id)
コード例 #29
0
async def main(timer: func.TimerRequest, starter: str):
    """
    Pulls up a new instance of AcmeRenewCoordinator.
    """
    client = df.DurableOrchestrationClient(starter)
    await client.start_new("AcmeRenewCoordinator")
コード例 #30
0
ファイル: __init__.py プロジェクト: jbold569/data-science
async def main(timer: func.TimerRequest, starter: str) -> None:
    client = df.DurableOrchestrationClient(starter)
    instance_id = await client.start_new("CovidOrchestrator", None, None)

    logging.info(f"Started orchestration with ID = '{instance_id}'.")