Skip to content
Permalink
Browse files

Added pings from retainer tasks to the server.

  • Loading branch information
thisisdhaas committed Jun 18, 2015
1 parent 63ad036 commit 01bb3f54afe10458012bfa17d839752518ede3e0
@@ -6,21 +6,21 @@ var Retainer = {
hid: null,
ping_type: 'waiting',

init: function(worker_id, assignment_id, hit_id){
init: function(worker_id, assignment_id, task_id){
Retainer.aid = assignment_id
Retainer.wid = worker_id
Retainer.hid = hit_id
Retainer.tid = task_id

Retainer.ping(worker_id, assignment_id, hit_id, Retainer.ping_type)
Retainer.ping(worker_id, assignment_id, task_id, Retainer.ping_type)
Retainer.checkForWork(assignment_id)
},

ping: function(worker_id, assignment_id, hit_id, ping_type){
$.get(PING_ENDPOINT +
'worker/' + worker_id + '/assignment/' + assignment_id + '/hit/' + hit_id + '/event/' + ping_type,
ping: function(worker_id, assignment_id, task_id, ping_type){
$.post(PING_ENDPOINT +
'worker/' + worker_id + '/task/' + task_id + '/event/' + ping_type,
function(data, status){
console.log('pong', data)
setTimeout(Retainer.ping, PING_INTERVAL, worker_id, assignment_id, hit_id, Retainer.ping_type)
setTimeout(Retainer.ping, PING_INTERVAL, worker_id, assignment_id, task_id, Retainer.ping_type)
}
)
},
@@ -21,7 +21,7 @@
{{ block.super }}

// Initialize the retainer object
PING_ENDPOINT = "todo"
PING_ENDPOINT = "/crowds/{{ crowd_name }}/retainer/ping/"
WORK_ENDPOINT = "todo"
PING_INTERVAL = 2500
WORK_INTERVAL = 1000
@@ -8,4 +8,6 @@
url(r'^(\w+)/responses/$', views.post_response, name='post_response'),
url(r'^(\w+)/tasks/$', views.create_task_group, name='create_tasks'),
url(r'^(\w+)/purge_tasks/$', views.purge_tasks, name='purge_tasks'),
url(r'^(?P<crowd_name>\w+)/retainer/ping/worker/(?P<worker_id>.+)/task/(?P<task_id>.+)/event/(?P<ping_type>.+)$',
views.ping, name='ping'),
)
@@ -1,5 +1,6 @@
from django.template import RequestContext, TemplateDoesNotExist
from django.template.loader import get_template, select_template
from django.utils import timezone
from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_GET, require_POST
@@ -221,7 +222,8 @@ def get_assignment(request, crowd_name):
context.update(group_context=group_context,
content=content,
backend_submit_url=interface.get_backend_submit_url(),
frontend_submit_url=interface.get_frontend_submit_url(crowd_config))
frontend_submit_url=interface.get_frontend_submit_url(crowd_config),
crowd_name=crowd_name)

# Load the template and render it.
template = get_scoped_template(crowd_name, current_task.task_type + '.html',
@@ -288,3 +290,20 @@ def post_response(request, crowd_name):
gather_answer.delay(current_task.task_id, model_spec)

return HttpResponse('ok') # AJAX call succeded.

# Views related to Retainer Pool tasks
#######################################

@require_POST
@csrf_exempt
def ping(request, crowd_name, worker_id, task_id, ping_type):
interface, model_spec = CrowdRegistry.get_registry_entry(crowd_name)
task = model_spec.task_model.objects.get(task_id=task_id)
worker = model_spec.worker_model.objects.get(worker_id=worker_id)

# TODO: track ping type?
# TODO: make this not broken when a worker is in multiple pools
worker.last_ping = timezone.now()
worker.save()

return HttpResponse('ok')

0 comments on commit 01bb3f5

Please sign in to comment.
You can’t perform that action at this time.