def connect(host, port, dst_tube): """connect to beanstalk, use dst_tube tube.""" beanstalk = Connection(host, port)) print("tubes:", beanstalk.tubes()) print("switching to", beanstalk.use(dst_tube)) print("now using", beanstalk.using()) return beanstalk
def push_city_jobs(city, sample_order): """get image download jobs for a city from job api then push them to image download queue.""" dst_tube = 'backlog_' + city.replace(' ', '_').lower() beanstalk = Connection(host='localhost', port=11300) print("tubes:", beanstalk.tubes()) print("switching to", beanstalk.use(dst_tube)) print("now using", beanstalk.using()) job_api = API() ok, jobs = job_api.jobs(city, sample_order) if not ok: return 0 for job in jobs: job_json = json.dumps(job) beanstalk.put(job_json) print("pushed {}_{}_{}_{}".format(job['city'], job['osm_way_id'], job['sequence'], job['cam_dir'])) beanstalk.close() return len(jobs)
#!/usr/bin/env python3 from pystalkd.Beanstalkd import Connection import notification import pickle import base64 setup = { 'connection': ('localhost', 11300), 'tubes': { 'use': 'python', 'ignore': ['default'], } } c = Connection(*setup['connection']) c.use(setup['tubes']['use']) print("Using tube {}".format(c.using())) notifications = [] notifications.append(notification.Notification("*****@*****.**", "Hello")) for notification in notifications: thing = pickle.dumps(notification) # beanstalk jobs only allows str objects body = base64.b64encode(thing) c.put(body.decode('ascii'))
#!/usr/bin/env python3 from pystalkd.Beanstalkd import Connection import notification import pickle import base64 setup = { 'connection': ('localhost', 11300), 'tubes': { 'use': 'python', 'ignore': ['default'], } } c = Connection(*setup['connection']) c.use(setup['tubes']['use']) print("Using tube {}".format(c.using())) notifications = [] notifications.append(notification.Notification("*****@*****.**", "Hello")) for notification in notifications: thing = pickle.dumps(notification) # beanstalk jobs only allows str objects body = base64.b64encode(thing) c.put(body.decode('ascii'))
from pystalkd.Beanstalkd import Connection beanstalk = Connection(host='localhost', port=11300) print("tubes:", beanstalk.tubes()) print("switching to", beanstalk.use('manchester')) print("now using", beanstalk.using()) print("sending job...") beanstalk.put("meh")