couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1142265 - in /couchdb/trunk: share/www/status.html src/couchdb/couch_task_status.erl
Date Sat, 02 Jul 2011 18:57:01 GMT
Author: fdmanana
Date: Sat Jul  2 18:57:00 2011
New Revision: 1142265

URL: http://svn.apache.org/viewvc?rev=1142265&view=rev
Log:
Add datetime fields to task statuses

Now task statuses have the fields "started" and "updated",
which are unix timestamps that reflect when a task was
started and when it was last updated.
The Status page of Futon was also updated with 2 new
columns to display these fields.

This closes COUCHDB-1201.


Modified:
    couchdb/trunk/share/www/status.html
    couchdb/trunk/src/couchdb/couch_task_status.erl

Modified: couchdb/trunk/share/www/status.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/status.html?rev=1142265&r1=1142264&r2=1142265&view=diff
==============================================================================
--- couchdb/trunk/share/www/status.html (original)
+++ couchdb/trunk/share/www/status.html Sat Jul  2 18:57:00 2011
@@ -42,6 +42,8 @@ specific language governing permissions 
         <thead><tr>
           <th>Type</th>
           <th>Object</th>
+          <th>Started on</th>
+          <th>Last updated on</th>
           <th>PID</th>
           <th>Status</th>
         </tr></thead>
@@ -51,6 +53,15 @@ specific language governing permissions 
     </div>
   </div></body>
   <script>
+    function toTaskDate(timestamp) {
+      var d = new Date(timestamp * 1000);
+      var hours = d.getHours(), min = d.getMinutes(), secs = d.getSeconds();
+      var year = d.getFullYear(), month = d.getMonth(), day = d.getDate();
+
+      return String(year) + "-" + (month < 10 ? "0" + month : month) + "-" +
+        day + " " + (hours < 10 ? "0" + hours : hours) + ":" +
+        (min < 10 ? "0" + min : min) + ":" + (secs < 10 ? "0" + secs : secs);
+    }
     var refreshTimeout = null;
 
     $.futon.storage.declare("poll_interval", {defaultValue: 5});
@@ -61,13 +72,17 @@ specific language governing permissions 
           clearTimeout(refreshTimeout);
           $("#status tbody.content").empty();
           if (!tasks.length) {
-            $("<tr class='none'><th colspan='4'>No tasks running</th></tr>")
+            $("<tr class='none'><th colspan='6'>No tasks running</th></tr>")
               .appendTo("#status tbody.content");
           } else {
             $.each(tasks, function(idx, task) {
-              $("<tr><th></th><td class='object'></td><td
class='pid'></td><td class='status'></td></tr>")
+              $("<tr><th></th><td class='object'></td><td
class='started'>" +
+                "</td><td class='updated'></td><td class='pid'></td>"
+
+                "<td class='status'></td></tr>")
                 .find("th").text(task.type).end()
                 .find("td.object").text(task.task).end()
+                .find("td.started").text(toTaskDate(task.started_on)).end()
+                .find("td.updated").text(toTaskDate(task.updated_on)).end()
                 .find("td.pid").text(task.pid).end()
                 .find("td.status").text(task.status).end()
                 .appendTo("#status tbody.content");

Modified: couchdb/trunk/src/couchdb/couch_task_status.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_task_status.erl?rev=1142265&r1=1142264&r2=1142265&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_task_status.erl (original)
+++ couchdb/trunk/src/couchdb/couch_task_status.erl Sat Jul  2 18:57:00 2011
@@ -29,6 +29,14 @@
 
 -include("couch_db.hrl").
 
+-record(task_status, {
+    type,
+    name,
+    start_ts,
+    update_ts,
+    status
+}).
+
 
 start_link() ->
     gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
@@ -44,11 +52,16 @@ all() ->
 
 add_task(Type, TaskName, StatusText) ->
     put(task_status_update, {{0, 0, 0}, 0}),
+    Ts = now_ts(),
     Msg = {
         add_task,
-        to_binary(Type),
-        to_binary(TaskName),
-        to_binary(StatusText)
+        #task_status{
+            type = to_binary(Type),
+            name = to_binary(TaskName),
+            status = to_binary(StatusText),
+            start_ts = Ts,
+            update_ts = Ts
+        }
     },
     gen_server:call(?MODULE, Msg).
 
@@ -82,10 +95,10 @@ terminate(_Reason,_State) ->
     ok.
 
 
-handle_call({add_task, Type, TaskName, StatusText}, {From, _}, Server) ->
+handle_call({add_task, TaskStatus}, {From, _}, Server) ->
     case ets:lookup(?MODULE, From) of
     [] ->
-        true = ets:insert(?MODULE, {From, {Type, TaskName, StatusText}}),
+        true = ets:insert(?MODULE, {From, TaskStatus}),
         erlang:monitor(process, From),
         {reply, ok, Server};
     [_] ->
@@ -94,21 +107,24 @@ handle_call({add_task, Type, TaskName, S
 handle_call(all, _, Server) ->
     All = [
         [
-            {type, Type},
-            {task, Task},
-            {status, Status},
+            {type, Task#task_status.type},
+            {task, Task#task_status.name},
+            {started_on, Task#task_status.start_ts},
+            {updated_on, Task#task_status.update_ts},
+            {status, Task#task_status.status},
             {pid, ?l2b(pid_to_list(Pid))}
         ]
         ||
-        {Pid, {Type, Task, Status}} <- ets:tab2list(?MODULE)
+        {Pid, Task} <- ets:tab2list(?MODULE)
     ],
     {reply, All, Server}.
 
 
 handle_cast({update_status, Pid, StatusText}, Server) ->
-    [{Pid, {Type, TaskName, _StatusText}}] = ets:lookup(?MODULE, Pid),
+    [{Pid, #task_status{name = TaskName} = Task}] = ets:lookup(?MODULE, Pid),
     ?LOG_DEBUG("New task status for ~s: ~s",[TaskName, StatusText]),
-    true = ets:insert(?MODULE, {Pid, {Type, TaskName, StatusText}}),
+    NewTaskStatus = Task#task_status{status = StatusText, update_ts = now_ts()},
+    true = ets:insert(?MODULE, {Pid, NewTaskStatus}),
     {noreply, Server};
 handle_cast(stop, State) ->
     {stop, normal, State}.
@@ -122,3 +138,7 @@ handle_info({'DOWN', _MonitorRef, _Type,
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
 
+
+now_ts() ->
+    {Mega, Secs, _} = erlang:now(),
+    Mega * 1000000 + Secs.



Mime
View raw message