summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/jobs.py
diff options
context:
space:
mode:
authorNathan Fritz <nathan@andyet.net>2010-06-01 21:45:15 -0700
committerNathan Fritz <nathan@andyet.net>2010-06-01 21:45:15 -0700
commit18e27d65ce47d877d6b2c810979df640aba7d8ba (patch)
tree942ed2d45a54e830d6e7c005e3f872c480477866 /sleekxmpp/plugins/jobs.py
parent0c39567f208db4938614e9723901037d8801fb25 (diff)
parentaa916c9ac893a976c8e26ee07ca4a9768a5e1680 (diff)
downloadslixmpp-18e27d65ce47d877d6b2c810979df640aba7d8ba.tar.gz
slixmpp-18e27d65ce47d877d6b2c810979df640aba7d8ba.tar.bz2
slixmpp-18e27d65ce47d877d6b2c810979df640aba7d8ba.tar.xz
slixmpp-18e27d65ce47d877d6b2c810979df640aba7d8ba.zip
Merge branch 'develop' of github.com:fritzy/SleekXMPP into develop
Diffstat (limited to 'sleekxmpp/plugins/jobs.py')
-rw-r--r--sleekxmpp/plugins/jobs.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/sleekxmpp/plugins/jobs.py b/sleekxmpp/plugins/jobs.py
new file mode 100644
index 00000000..bb2e2554
--- /dev/null
+++ b/sleekxmpp/plugins/jobs.py
@@ -0,0 +1,44 @@
+from . import base
+import logging
+from xml.etree import cElementTree as ET
+
+class jobs(base.base_plugin):
+ def plugin_init(self):
+ self.xep = 'pubsubjob'
+ self.description = "Job distribution over Pubsub"
+
+ def post_init(self):
+ pass
+ #TODO add event
+
+ def createJobNode(self, host, jid, node, config=None):
+ pass
+
+ def createJob(self, host, node, jobid=None, payload=None):
+ return self.xmpp.plugin['xep_0060'].setItem(host, node, ((jobid, payload),))
+
+ def claimJob(self, host, node, jobid, ifrom=None):
+ return self._setState(host, node, jobid, ET.Element('{http://andyet.net/protocol/pubsubjob}claimed'))
+
+ def unclaimJob(self, jobid):
+ return self._setState(host, node, jobid, ET.Element('{http://andyet.net/protocol/pubsubjob}unclaimed'))
+
+ def finishJob(self, host, node, jobid, payload=None):
+ finished = ET.Element('{http://andyet.net/protocol/pubsubjob}finished')
+ if payload is not None:
+ finished.append(payload)
+ return self._setState(host, node, jobid, finished)
+
+ def _setState(self, host, node, jobid, state, ifrom=None):
+ iq = self.xmpp.Iq()
+ iq['to'] = host
+ if ifrom: iq['from'] = ifrom
+ iq['type'] = 'set'
+ iq['psstate']['node'] = node
+ iq['psstate']['item'] = jobid
+ iq['psstate']['payload'] = state
+ result = iq.send()
+ if result is None or result['type'] != 'result':
+ return False
+ return True
+