Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a small YAML parser, which should be sufficient for most purposes. #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

None yet

1 participant