
import json

import requests

import stoneridge


@stoneridge.main
def main():
    parser = stoneridge.ArgumentParser()
    parser.parse_args()

    root = stoneridge.get_config('enqueuer', 'root')
    username = stoneridge.get_config('enqueuer', 'username')
    password = stoneridge.get_config('enqueuer', 'password')

    res = requests.get(root + '/list_unhandled', auth=(username, password))
    queue = json.loads(res.text)

    for entry in queue:
        stoneridge.enqueue(nightly=False, ldap=entry['ldap'], sha=entry['sha'],
                netconfigs=entry['netconfigs'],
                operating_systems=entry['operating_systems'],
                srid=entry['srid'])
        requests.post(root + '/mark_handled', data={'id': entry['pushid']},
                auth=(username, password))


import json

import requests

import stoneridge


@stoneridge.main
def main():
    parser = stoneridge.ArgumentParser()
    parser.parse_args()

    root = stoneridge.get_config('enqueuer', 'root')
    username = stoneridge.get_config('enqueuer', 'username')
    password = stoneridge.get_config('enqueuer', 'password')

    try:
        res = requests.get(root + '/list_unhandled', auth=(username, password))
    except:
        # For some reason, we sometimes get a requests failure here, even though
        # everything seems to be working fine. Ignore that, and try again later.
        return

    queue = json.loads(res.text)

    for entry in queue:
        try:
            requests.post(root + '/mark_handled', data={'id': entry['pushid']},
                    auth=(username, password))
        except:
            # If we fail to mark this as handled, wait until the next try so we
            # don't run the same thing more than once. It's not the end of the
            # world ot have to wait...
            return

        stoneridge.enqueue(nightly=False, ldap=entry['ldap'], sha=entry['sha'],
                netconfigs=entry['netconfigs'],
                operating_systems=entry['operating_systems'],
                srid=entry['srid'])

Handle exceptions better in enqueuer
Handle exceptions better in enqueuer

We don't care too much, so just swallow them. People will complain at me
if their "pushed" jobs don't get run (eventually).

  
  import json
  
  import requests
  
  import stoneridge
  
  
  @stoneridge.main
  def main():
      parser = stoneridge.ArgumentParser()
      parser.parse_args()
  
      root = stoneridge.get_config('enqueuer', 'root')
      username = stoneridge.get_config('enqueuer', 'username')
      password = stoneridge.get_config('enqueuer', 'password')
  
+     try:
-     res = requests.get(root + '/list_unhandled', auth=(username, password))
+         res = requests.get(root + '/list_unhandled', auth=(username, password))
+     except:
+         # For some reason, we sometimes get a requests failure here, even though
+         # everything seems to be working fine. Ignore that, and try again later.
+         return
+ 
      queue = json.loads(res.text)
  
      for entry in queue:
+         try:
+             requests.post(root + '/mark_handled', data={'id': entry['pushid']},
+                     auth=(username, password))
+         except:
+             # If we fail to mark this as handled, wait until the next try so we
+             # don't run the same thing more than once. It's not the end of the
+             # world ot have to wait...
+             return
+ 
          stoneridge.enqueue(nightly=False, ldap=entry['ldap'], sha=entry['sha'],
                  netconfigs=entry['netconfigs'],
                  operating_systems=entry['operating_systems'],
                  srid=entry['srid'])
-         requests.post(root + '/mark_handled', data={'id': entry['pushid']},
-                 auth=(username, password))
  
Handle exceptions better in enqueuer
## Code Before:

import json

import requests

import stoneridge


@stoneridge.main
def main():
    parser = stoneridge.ArgumentParser()
    parser.parse_args()

    root = stoneridge.get_config('enqueuer', 'root')
    username = stoneridge.get_config('enqueuer', 'username')
    password = stoneridge.get_config('enqueuer', 'password')

    res = requests.get(root + '/list_unhandled', auth=(username, password))
    queue = json.loads(res.text)

    for entry in queue:
        stoneridge.enqueue(nightly=False, ldap=entry['ldap'], sha=entry['sha'],
                netconfigs=entry['netconfigs'],
                operating_systems=entry['operating_systems'],
                srid=entry['srid'])
        requests.post(root + '/mark_handled', data={'id': entry['pushid']},
                auth=(username, password))

## Instruction:
Handle exceptions better in enqueuer
## Code After:

import json

import requests

import stoneridge


@stoneridge.main
def main():
    parser = stoneridge.ArgumentParser()
    parser.parse_args()

    root = stoneridge.get_config('enqueuer', 'root')
    username = stoneridge.get_config('enqueuer', 'username')
    password = stoneridge.get_config('enqueuer', 'password')

    try:
        res = requests.get(root + '/list_unhandled', auth=(username, password))
    except:
        # For some reason, we sometimes get a requests failure here, even though
        # everything seems to be working fine. Ignore that, and try again later.
        return

    queue = json.loads(res.text)

    for entry in queue:
        try:
            requests.post(root + '/mark_handled', data={'id': entry['pushid']},
                    auth=(username, password))
        except:
            # If we fail to mark this as handled, wait until the next try so we
            # don't run the same thing more than once. It's not the end of the
            # world ot have to wait...
            return

        stoneridge.enqueue(nightly=False, ldap=entry['ldap'], sha=entry['sha'],
                netconfigs=entry['netconfigs'],
                operating_systems=entry['operating_systems'],
                srid=entry['srid'])
