Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ptjm
Copy link

@ptjm ptjm commented Jul 23, 2014

If parse_yaml is True and PyYAML is not available, this change fails over to a small built-in parser which handles the syntax returned by beanstalkd. For example:

>>> import beanstalkc
>>> import pprint
>>> bs = beanstalkc.Connection()
>>> pprint(bs.stats())
{'binlog-current-index': 0,
 'binlog-max-size': 10485760,
 ...
 'current-jobs-buried': 0,
 'current-jobs-delayed': 0,
 'current-jobs-ready': 0,
 'current-jobs-reserved': 0,
 ...
 'rusage-stime': '0.008396',
 'rusage-utime': '0.000000',
 ...
 'version': '1.9'}
>>> bs.use('t1')
't1'
>>> bs.watch('t1')
2
>>> bs.using()
't1'
>>> bs.watching()
['default', 't1']
>>> bs.put('a job for t1', priority = 56)
6
>>> j = bs.reserve()
>>> pprint(j.stats())
{'age': 9,
 'buries': 0,
 'delay': 0,
 'file': 0,
 'id': 6,
 'kicks': 0,
 'pri': 56,
 'releases': 0,
 'reserves': 1,
 'state': 'reserved',
 'time-left': 118,
 'timeouts': 0,
 'ttr': 120,
 'tube': 't1'}
>>> j.release()
>>> j = bs.reserve()
>>> pprint(j.stats())
{'age': 68,
 'buries': 0,
 'delay': 0,
 'file': 0,
 'id': 6,
 'kicks': 0,
 'pri': 56,
 'releases': 1,
 'reserves': 2,
 'state': 'reserved',
 'time-left': 115,
 'timeouts': 0,
 'ttr': 120,
 'tube': 't1'}
>>> pprint(bs.stats_tube('t1'))
{'cmd-delete': 1,
 'cmd-pause-tube': 0,
 'current-jobs-buried': 0,
 'current-jobs-delayed': 0,
 'current-jobs-ready': 0,
 'current-jobs-reserved': 1,
 'current-jobs-urgent': 0,
 'current-using': 1,
 'current-waiting': 0,
 'current-watching': 1,
 'name': 't1',
 'pause': 0,
 'pause-time-left': 0,
 'total-jobs': 2}
>>> for i in range(1,bs.stats()['total-jobs']+1):
...  try:
...   bs.delete(i)
...   print i
...  except: pass
... 
6

I believe the parsed result is identical to what PyYAML gives for the same input, with the exception of the rusage and version keys, which this code leaves as strings. This would affect someone graphing rusage, but not most people.

i.e., it returns lists as lists and stats output as dicts; it preserves
priority on release() and allows numeric testing of ttl.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant