-
Notifications
You must be signed in to change notification settings - Fork 0
/
cctasks.js
121 lines (112 loc) · 3.79 KB
/
cctasks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Some helpers for running Cybercommons Tasks
// Should point to queue submission target
// Configuration object for calling cybercom queue tasks.
// Parameters can be specified in [params] list object, or a special list of
// jQuery selectors can be provided to grab the current values of these form elements at run-time.
/*
taskdesc = {
"taskname": 'cybercomq.static.tasks.modiscountry',
"taskq": 'static',
"params": ['MOD09A1_ndvi','MX','2010-10-10','2010-11-1'], // Fixed params
"uiparams": ['#product','#country','#start_date','#end_date'],// UI Selected
"status": '#status',
"spinner": '#spinner',
"pollinterval": 2000,
}
*/
// Called by call task to poll queue status of task based on task_id
var QUEUE_SUBMIT = '/queue/run/';
var QUEUE_POLL = '/queue/task/';
function test_auth_tkt () {
$("#auth_dialog").hide();
if ($.cookie('auth_tkt')) {
$('#auth_message').html("you're logged in")
}
else {
$("#auth_dialog").dialog({ height: 200, modal: true});
$("#auth_dialog").dialog("open");
$('#auth_message').html('Please <a href="http://test.cybercommons.org/accounts/login/">login</a> to track your tasks via the cybercommons').addClass('label warning');
}
}
function poll_status (args) {
$.getJSON(args.host + args.task_id + '?callback=?', function (data) {
if (data.status == "PENDING") {
options1.onPending(args);
} else if (data.status == "FAILURE") {
options.onFailure(data);
} else if (data.status == "Error") {
options1.onFailure(data);
} else if (data.status == "ERROR") {
options1.onFailure(data);
} else if (data.status == "SUCCESS") {
options1.onSuccess(data);
}
});
}
function calltask (taskdesc) {
defaults = {
"service_host": QUEUE_SUBMIT,
"poll_target": QUEUE_POLL,
"status": '#status',
"spinner": '#spinner',
"pollinterval": 4000,
"onPending": function (task_id) {
$(options1.status).show();
$(options1.status).removeClass('label label-success label-warning label-important').addClass('label label-warning');
$(options1.status).text("Working...");
$(options1.spinner).show();
setTimeout(function () {
poll_status(task_id);
}, options1.pollinterval);
},
"onFailure": function (data) {
$(options1.status).show();
$(options1.status).removeClass('label label-success label-warning label-important').addClass('label label-important');
$(options1.status).text("Task failed!");
$(options1.spinner).hide();
},
"onSuccess": function (data) {
$(options1.status).show();
$(options1.status).removeClass('label label-success label-warning label-important').addClass('label label-success');
$(options1.status).html('<a style="color:#fff" href="' + data.tombstone[0].result + '">Download</a>');
$(options1.spinner).hide();
simpleCart.empty();
//siteLayer.styleMap = myStyles1;
//siteLayer.redraw();
}
}
options1 = $.extend(true, {}, defaults, taskdesc)
var taskparams = "";
if (options1.params) {
for (item in options1.params) {
taskparams = taskparams.concat('/' + options1.params[item]);
}
} else if (options1.uiparams) {
for (item in options1.uiparams) {
taskparams = taskparams.concat('/' + $(options1.uiparams[item]).val());
}
}
var kwargs = "?";
if (options1.kwargs) {
for (var key in options1.kwargs) {
kwargs = kwargs + key + '=' + options1.kwargs[key] + '&';
}
}
var taskcall = "";
if (options1.taskq) {
taskcall = options1.taskname + '@' + options1.taskq;
} else {
taskcall = options1.taskname;
}
var request = options1.service_host + taskcall + taskparams + kwargs;
$.getJSON(request + 'callback=?', function (data) {
$(options1.status).text('Task submitted...');
var task_id = data.task_id;
setTimeout(function () {
var poll = {};
poll.host = options1.poll_target;
poll.task_id = task_id;
poll_status(poll);
}, taskparams.pollinterval);
});
}