Exemplo n.º 1
0
def create_test(request):
    resp = {'result': "success", 'code': 0, 'message': ""}
    print('received an http request: create test!')
    print('request.body == %s' % request.body)

    args = simplejson.loads(request.body)
    tm = TaskManager()
    tm.create_test(args, resp)

    respstr = simplejson.dumps(resp)
    print(respstr)
    return HttpResponse(respstr)
Exemplo n.º 2
0
def get_task_history(request):
    resp = {'result': "success", 'code': 0, 'message': ""}
    print('received an http request: get task history!')
    print('request.body == %s' %request.body)

    args = simplejson.loads(request.body)
    tm = TaskManager()
    tm.get_task_history(args, resp)

    respstr = simplejson.dumps(resp)
    print(respstr)
    return HttpResponse(respstr)
Exemplo n.º 3
0
def submit_result(request):
    resp = {'result': "success", 'code': 0,
            'message': "task result is submitted successfully"}
    print('received an http request: submit task result!')
    print('request.body == %s' %request.body)

    taskSubmit = simplejson.loads(request.body)
    tm = TaskManager()
    tm.submit_result(taskSubmit, resp)

    respstr = simplejson.dumps(resp)
    print(respstr)
    return HttpResponse(respstr)
Exemplo n.º 4
0
def get_task_questions(request):
    resp = {'result': "success", 'code': 0,
            'message': "task detail is fetched successfully"}
    print('received an http request: get task detail!')
    print('request.body == %s' %request.body)

    req = simplejson.loads(request.body)
    taskid = req['taskId']
    tm = TaskManager()
    tm.get_task_questions(taskid, resp)

    respstr = simplejson.dumps(resp)
    print(respstr)
    return HttpResponse(respstr)
def main():

    # create the api client
    client = client_module.RestApiClient(version='7.0')

    # -------------------------------------------------------------------------
    # 1. get a list of flow regex property
    endpoint_url = 'config/flow_sources/custom_properties/regex_properties'
    http_method = 'GET'

    # select fields to return for each flow regex property
    fields = 'id, name, property_type'

    # use filter to select desired flow regex property
    query_filter = 'property_type = "numeric"'

    # populate the optional parameters to be used in request
    params = {'fields': fields, 'filter': query_filter}

    # put range in header for paging purpose
    headers = {'range': 'items=0-4'}

    # send the request
    response = client.call_api(endpoint_url, http_method, params=params,
                               headers=headers, print_request=True)

    # check response and handle any error
    if response.code == 200:
        regex_properties = json.loads(response.read().decode('utf-8'))

        # go through the list of flow regex properties and print each
        for regex_property in regex_properties:
            print(regex_property)

    else:
        SampleUtilities.pretty_print_response(response)
        print('Failed to retrieve the list of flow regex properties')
        sys.exit(1)

    # -------------------------------------------------------------------------
    # 2. create a new flow regex property

    endpoint_url = 'config/flow_sources/custom_properties/regex_properties'
    http_method = 'POST'

    # sample flow regex property, be sure to change the name if running
    # multiple times.
    new_regex_property = {
                          "name": "Sample flow regex property x",
                          "description": "description property",
                          "property_type": "numeric",
                          "use_for_rule_engine": True,
                          }

    data = json.dumps(new_regex_property).encode('utf-8')

    headers = {'Content-type': 'application/json'}

    # send the request
    response = client.call_api(endpoint_url, http_method, data=data,
                               headers=headers, print_request=True)

    # check response and handle any error
    if response.code == 201:
        print('A new flow regex property is created.')
        # can extract newly created flow regex property from the response
        regex_property = json.loads(response.read().decode('utf-8'))
        print(json.dumps(regex_property, indent=4))
    else:
        print('Failed to create the new flow regex property')
        SampleUtilities.pretty_print_response(response)
        sys.exit(1)

    # -------------------------------------------------------------------------
    # 3. get a single flow regex property by id

    # id of the flow regex property, using the one created in step 2
    regex_property_id = regex_property['id']

    endpoint_url = ('config/flow_sources/custom_properties/regex_properties' +
                    '/' + str(regex_property_id))
    http_method = 'GET'

    # send the request
    response = client.call_api(endpoint_url, http_method, print_request=True)

    # check response and handle any error
    if response.code == 200:
        print("The requested flow regex property has been retrieved.")
        regex_property = json.loads(response.read().decode('utf-8'))
        print(json.dumps(regex_property, indent=4))
    else:
        print('Failed to retrieve the flow regex property with id=' +
              str(regex_property_id))
        SampleUtilities.pretty_print_response(response)
        sys.exit(1)

    # -------------------------------------------------------------------------
    # 4. update a flow regex property by its id

    # using flow regex property created in step 2
    regex_property_id = regex_property['id']

    endpoint_url = ('config/flow_sources/custom_properties/regex_properties' +
                    '/' + str(regex_property_id))
    http_method = 'POST'

    fields_to_update = {
                        "description": "updated description",
                        "use_for_rule_engine": False,
                        }

    data = json.dumps(fields_to_update).encode('utf-8')

    headers = {'Content-type': 'application/json'}

    # send the request
    response = client.call_api(endpoint_url, http_method, data=data,
                               headers=headers, print_request=True)

    if response.code == 200:
        print('The flow regex property has been successfully updated.')
        regex_property = json.loads(response.read().decode('utf-8'))
        print(json.dumps(regex_property, indent=4))
    else:
        print('Failed to update the flow regex property with id=' +
              str(regex_property_id))
        SampleUtilities.pretty_print_response(response)
        sys.exit(1)

    # -------------------------------------------------------------------------
    # 5. find dependents of a flow regex property

    # using flow regex property created in step 2
    regex_property_id = regex_property['id']

    endpoint_url = ('config/flow_sources/custom_properties/regex_properties' +
                    '/' + str(regex_property_id)) + '/dependents'
    http_method = 'GET'

    # send the request
    response = client.call_api(endpoint_url, http_method, print_request=True)

    if response.code == 202:
        print('The find dependents task for flow regex property has started.')
        task_status = json.loads(response.read().decode('utf-8'))
        print(json.dumps(task_status, indent=4))

        task_status_url = ('/config/flow_sources/custom_properties/' +
                           'regex_property_dependent_tasks' + '/' +
                           str(task_status['id']))

        task_manager = TaskManager(client, task_status_url)

        try:
            task_manager.wait_for_task_to_complete(60)

            # query the result endpoint for results

            endpoint_url = ('config/flow_sources/custom_properties/' +
                            'regex_property_dependent_tasks' + '/' +
                            str(task_status['id']) + '/results')
            http_method = 'GET'

            response = client.call_api(endpoint_url, http_method,
                                       print_request=True)

            # check response and handle any error
            if response.code == 200:
                task_result = json.loads(response.read().decode('utf-8'))
                print(json.dumps(task_result, indent=4))

            else:
                SampleUtilities.pretty_print_response(response)
                print('Failed to retrieve the result of find dependents task.')
                sys.exit(1)

        except TimeoutError:
            print("Find dependents task time out. Current status is:")
            SampleUtilities.pretty_print_response(
                              task_manager.get_task_status()
                              )

    else:
        print('Failed to start a find dependents task for ' +
              'flow regex property with id=' + str(regex_property_id))
        SampleUtilities.pretty_print_response(response)
        sys.exit(1)

    # -------------------------------------------------------------------------
    # 6. delete a flow regex property

    # using flow regex property created in step 2
    regex_property_id = regex_property['id']

    endpoint_url = ('config/flow_sources/custom_properties/regex_properties' +
                    '/' + str(regex_property_id))
    http_method = 'DELETE'

    # send the request
    response = client.call_api(endpoint_url, http_method, print_request=True)

    if response.code == 202:
        print('The deletion task for flow regex property has started.')
        task_status = json.loads(response.read().decode('utf-8'))
        print(json.dumps(task_status, indent=4))

        task_status_url = ('/config/flow_sources/custom_properties/' +
                           'regex_property_delete_tasks' + '/' +
                           str(task_status['id']))

        task_manager = TaskManager(client, task_status_url)

        try:
            task_manager.wait_for_task_to_complete(60)
        except TimeoutError:
            print("Deletion task time out. Current status is:")
            SampleUtilities.pretty_print_response(
                              task_manager.get_task_status()
                              )

    else:
        print('Failed to start a deletion task for ' +
              'flow regex property with id=' + str(regex_property_id))
        SampleUtilities.pretty_print_response(response)
        sys.exit(1)
Exemplo n.º 6
0
    ll = []
    for project in data:
        ll.append(project)
    return ll


def func2(data):
    [write_queue.put(obj) for obj in data]


def hole(data):
    pass


data_manager = get_projects
task_manager = TaskManager(data_manager, message_queue)
task_manager.run()


class Telegram:
    def __init__(self, token):
        self.token = token
        self.update_id = None
        self.api_url = "https://api.telegram.org/bot{}/".format(token)
        self.timeout = 10
        self.W = 0

    def get_updates(self):
        while True:
            method = 'getUpdates'
            params = {'timeout': self.timeout, 'offset': self.update_id}
Exemplo n.º 7
0
def main():

    # create the api client
    client = client_module.RestApiClient(version='7.0')

    # -------------------------------------------------------------------------
    # 1. get a list of flow regex property
    endpoint_url = 'config/flow_sources/custom_properties/regex_properties'
    http_method = 'GET'

    # select fields to return for each flow regex property
    fields = 'id, name, property_type'

    # use filter to select desired flow regex property
    query_filter = 'property_type = "numeric"'

    # populate the optional parameters to be used in request
    params = {'fields': fields, 'filter': query_filter}

    # put range in header for paging purpose
    headers = {'range': 'items=0-4'}

    # send the request
    response = client.call_api(endpoint_url,
                               http_method,
                               params=params,
                               headers=headers,
                               print_request=True)

    # check response and handle any error
    if response.code == 200:
        regex_properties = json.loads(response.read().decode('utf-8'))

        # go through the list of flow regex properties and print each
        for regex_property in regex_properties:
            print(regex_property)

    else:
        SampleUtilities.pretty_print_response(response)
        print('Failed to retrieve the list of flow regex properties')
        sys.exit(1)

    # -------------------------------------------------------------------------
    # 2. create a new flow regex property

    endpoint_url = 'config/flow_sources/custom_properties/regex_properties'
    http_method = 'POST'

    # sample flow regex property, be sure to change the name if running
    # multiple times.
    new_regex_property = {
        "name": "Sample flow regex property x",
        "description": "description property",
        "property_type": "numeric",
        "use_for_rule_engine": True,
    }

    data = json.dumps(new_regex_property).encode('utf-8')

    headers = {'Content-type': 'application/json'}

    # send the request
    response = client.call_api(endpoint_url,
                               http_method,
                               data=data,
                               headers=headers,
                               print_request=True)

    # check response and handle any error
    if response.code == 201:
        print('A new flow regex property is created.')
        # can extract newly created flow regex property from the response
        regex_property = json.loads(response.read().decode('utf-8'))
        print(json.dumps(regex_property, indent=4))
    else:
        print('Failed to create the new flow regex property')
        SampleUtilities.pretty_print_response(response)
        sys.exit(1)

    # -------------------------------------------------------------------------
    # 3. get a single flow regex property by id

    # id of the flow regex property, using the one created in step 2
    regex_property_id = regex_property['id']

    endpoint_url = ('config/flow_sources/custom_properties/regex_properties' +
                    '/' + str(regex_property_id))
    http_method = 'GET'

    # send the request
    response = client.call_api(endpoint_url, http_method, print_request=True)

    # check response and handle any error
    if response.code == 200:
        print("The requested flow regex property has been retrieved.")
        regex_property = json.loads(response.read().decode('utf-8'))
        print(json.dumps(regex_property, indent=4))
    else:
        print('Failed to retrieve the flow regex property with id=' +
              str(regex_property_id))
        SampleUtilities.pretty_print_response(response)
        sys.exit(1)

    # -------------------------------------------------------------------------
    # 4. update a flow regex property by its id

    # using flow regex property created in step 2
    regex_property_id = regex_property['id']

    endpoint_url = ('config/flow_sources/custom_properties/regex_properties' +
                    '/' + str(regex_property_id))
    http_method = 'POST'

    fields_to_update = {
        "description": "updated description",
        "use_for_rule_engine": False,
    }

    data = json.dumps(fields_to_update).encode('utf-8')

    headers = {'Content-type': 'application/json'}

    # send the request
    response = client.call_api(endpoint_url,
                               http_method,
                               data=data,
                               headers=headers,
                               print_request=True)

    if response.code == 200:
        print('The flow regex property has been successfully updated.')
        regex_property = json.loads(response.read().decode('utf-8'))
        print(json.dumps(regex_property, indent=4))
    else:
        print('Failed to update the flow regex property with id=' +
              str(regex_property_id))
        SampleUtilities.pretty_print_response(response)
        sys.exit(1)

    # -------------------------------------------------------------------------
    # 5. find dependents of a flow regex property

    # using flow regex property created in step 2
    regex_property_id = regex_property['id']

    endpoint_url = ('config/flow_sources/custom_properties/regex_properties' +
                    '/' + str(regex_property_id)) + '/dependents'
    http_method = 'GET'

    # send the request
    response = client.call_api(endpoint_url, http_method, print_request=True)

    if response.code == 202:
        print('The find dependents task for flow regex property has started.')
        task_status = json.loads(response.read().decode('utf-8'))
        print(json.dumps(task_status, indent=4))

        task_status_url = ('/config/flow_sources/custom_properties/' +
                           'regex_property_dependent_tasks' + '/' +
                           str(task_status['id']))

        task_manager = TaskManager(client, task_status_url)

        try:
            task_manager.wait_for_task_to_complete(60)

            # query the result endpoint for results

            endpoint_url = ('config/flow_sources/custom_properties/' +
                            'regex_property_dependent_tasks' + '/' +
                            str(task_status['id']) + '/results')
            http_method = 'GET'

            response = client.call_api(endpoint_url,
                                       http_method,
                                       print_request=True)

            # check response and handle any error
            if response.code == 200:
                task_result = json.loads(response.read().decode('utf-8'))
                print(json.dumps(task_result, indent=4))

            else:
                SampleUtilities.pretty_print_response(response)
                print('Failed to retrieve the result of find dependents task.')
                sys.exit(1)

        except TimeoutError:
            print("Find dependents task time out. Current status is:")
            SampleUtilities.pretty_print_response(
                task_manager.get_task_status())

    else:
        print('Failed to start a find dependents task for ' +
              'flow regex property with id=' + str(regex_property_id))
        SampleUtilities.pretty_print_response(response)
        sys.exit(1)

    # -------------------------------------------------------------------------
    # 6. delete a flow regex property

    # using flow regex property created in step 2
    regex_property_id = regex_property['id']

    endpoint_url = ('config/flow_sources/custom_properties/regex_properties' +
                    '/' + str(regex_property_id))
    http_method = 'DELETE'

    # send the request
    response = client.call_api(endpoint_url, http_method, print_request=True)

    if response.code == 202:
        print('The deletion task for flow regex property has started.')
        task_status = json.loads(response.read().decode('utf-8'))
        print(json.dumps(task_status, indent=4))

        task_status_url = ('/config/flow_sources/custom_properties/' +
                           'regex_property_delete_tasks' + '/' +
                           str(task_status['id']))

        task_manager = TaskManager(client, task_status_url)

        try:
            task_manager.wait_for_task_to_complete(60)
        except TimeoutError:
            print("Deletion task time out. Current status is:")
            SampleUtilities.pretty_print_response(
                task_manager.get_task_status())

    else:
        print('Failed to start a deletion task for ' +
              'flow regex property with id=' + str(regex_property_id))
        SampleUtilities.pretty_print_response(response)
        sys.exit(1)
Exemplo n.º 8
0
from discord.ext.commands import Bot
from taskManager import TaskManager

BOT_PREFIX = ("?", "!")
TOKEN = "NDgxMzIzNjYzNTMxMTgwMDMy.DmeOxg.fHCqzvlcIbXHg-5v58vAyys7t_E"  # Get at discordapp.com/developers/applications/me

client = Bot(command_prefix=BOT_PREFIX)
Manager = TaskManager()


@client.command(name='Hi',
                aliases=['hello', 'Hello', 'Yo', 'Good Evening', 'Konichiwa'],
                pass_context=True)
async def Hi(context):
    response = "Hi there, " + context.message.author.mention
    await client.say(response)


@client.command(pass_context=True)
async def CreateTask(context):
    await client.say(
        "Certainly, what is the name of the task you would like to make?")
    taskName = await client.wait_for_message(author=context.message.author)
    await client.say("and who is this task assigned to?")
    assignedTo = await client.wait_for_message(author=context.message.author)
    await client.say("Category?")
    category = await client.wait_for_message(author=context.message.author)
    await client.say("Asset type?")
    assetType = await client.wait_for_message(author=context.message.author)
    response = "You are creating a task with a name of " + str(
        taskName.content) + " and is assigned to " + str(
Exemplo n.º 9
0
                                                   planets)
                result.append(planet_pos)

        result_queue.put(result)
        job_queue.task_done()


def __start_workers(manager):
    job_queue, result_queue = manager.get_job_queue(
    ), manager.get_result_queue()
    nr_of_processes = cpu_count()
    processes = [
        Process(target=__worker_function, args=(job_queue, result_queue))
        for i in range(nr_of_processes)
    ]

    for p in processes:
        p.start()
    return nr_of_processes


if __name__ == "__main__":
    server_ip, server_socket = "141.82.173.24", 5003
    TaskManager.register('get_job_queue')
    TaskManager.register('get_result_queue')
    manager = TaskManager(address=(server_ip, server_socket),
                          authkey=b'secret')
    manager.connect()
    nr_of_processes = __start_workers(manager)
    print(nr_of_processes, 'workers started')