def main(mytimer: func.TimerRequest, msg: func.Out[typing.List[str]]) -> None:

    ethosClient = EllucianEthosPythonClient.EllucianEthosAPIClient(
        baseURL=os.environ["ethosBaseURL"])
    loginSession = ethosClient.getLoginSessionFromAPIKey(
        apiKey=os.environ["ethosAppAPIKey"])

    utc_timestamp = datetime.datetime.utcnow().replace(
        tzinfo=datetime.timezone.utc).isoformat()

    if mytimer.past_due:
        logging.info('The timer is past due!')

    logging.info('Requesting Change Notifications from Ethos at %s',
                 utc_timestamp)

    changeNotificationIterator = ethosClient.getChangeNotificationIterator(
        loginSession=loginSession, pageLimit=20, maxRequests=4)

    msgsReceived = []
    numNotifications = 0
    for curChangeNotification in changeNotificationIterator:
        numNotifications += 1
        msgsReceived.append(json.dumps(curChangeNotification.getSimpleDict()))

    msg.set(msgsReceived)

    logging.info('Complete - Notifications Processed: %s',
                 str(numNotifications))
 def test_nextTimeSimple(self):
     self.assertEqual(
         EllucianEthosPythonClient.getNextWorkerTime(
             lastRunTime=pytz.timezone('UTC').localize(
                 datetime.datetime(2020, 1, 14, 23, 3, second=5)),
             curTime=pytz.timezone('UTC').localize(
                 datetime.datetime(2020, 1, 14, 23, 3, second=10)),
             frequency=6),
         pytz.timezone('UTC').localize(
             datetime.datetime(2020, 1, 14, 23, 3, second=11)))
示例#3
0
    def test_simpleDictOutput(self):
        ethosClient = EllucianEthosPythonClient.EllucianEthosAPIClient(
            baseURL="MOCK")

        sampleFnCallResponse = {
            'id': '3764',
            'published': '2020-07-02 13:38:38.183489+00',
            'resource': {
                'name': 'person-holds',
                'id': 'c997507d-4f46-4cde-bee0-a75cc412e734',
                'version': 'application/vnd.hedtech.integration.v6+json'
            },
            'operation': 'created',
            'contentType': 'resource-representation',
            'content': {
                'endOn': '2099-12-31T00:00:00Z',
                'id': 'c997507d-4f46-4cde-bee0-a75cc412e734',
                'person': {
                    'id': '5bcbc3b1-cf8a-4ea6-9042-1dc3e14aa3ba'
                },
                'startOn': '2020-01-17T00:00:00Z',
                'type': {
                    'category': 'academic',
                    'detail': {
                        'id': '45182c89-6bb8-4996-a05a-6fce28f028eb'
                    }
                }
            },
            'publisher': {
                'id': '84592449-455b-40ea-9856-cb9e6878bd21',
                'applicationName': 'Imperial Student API - BILD'
            }
        }

        changeNotification = EllucianEthosPythonClient.ChangeNotificationMessage.ChangeNotificationMessage(
            dict=sampleFnCallResponse, clientAPIInstance=ethosClient)

        self.assertEqual(changeNotification.getSimpleDict(),
                         sampleFnCallResponse)
示例#4
0
 def setUp(self):
     self.ethosClient = EllucianEthosPythonClient.EllucianEthosAPIClient(
         baseURL=ethosBaseURL)
# This is a simple non-reliable implementation. All messages will be taken off the queue no matter if they are
# sucessfully processed or not.
import sys
import os

import EllucianEthosPythonClient
import queue
import time

ethosBaseURL = os.environ["ETHOSBASEURL"]
ethosPollerAppAPIKey = os.environ["ETHOSPOLLERAPIKEY"]
##ethosPollerAppAPIKey = os.environ["ICETHOSDEVAPIKEY"]

print("Start")

ethosClient = EllucianEthosPythonClient.EllucianEthosAPIClient(
    baseURL=ethosBaseURL)
loginSession = ethosClient.getLoginSessionFromAPIKey(
    apiKey=ethosPollerAppAPIKey)

changeNotificationQueue = queue.Queue()
ethosClient.startChangeNotificationPollerThread(
    loginSession=loginSession,
    frequency=10,  # number of seconds between fetches
    pageLimit=20,  # number of change notifications to get per requests
    maxRequests=4,  # maximum number of rquests to use in each fecth
    pollerQueue=changeNotificationQueue)

print("Starting to watch for messages - ctl+c to terminate")
try:
    while True:
        while changeNotificationQueue.qsize() > 0: