Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added update_new_task_2

  • Loading branch information...
commit b2b34fe52ca7163d964954f408d9f787c408670a 1 parent fe7577e
Makoto Inoue authored
Showing with 55 additions and 18 deletions.
  1. +16 −15 wait-table/test.rb
  2. +39 −3 wait-table/wait-table.lua
View
31 wait-table/test.rb
@@ -5,7 +5,6 @@
require 'pp'
t = TokyoTyrant::Table.new('127.0.0.1', 1978)
-
# bulk operations
h = {}
h[0] = { :name => 'A: Joe task one', :region => 'us', :priority => 2, :url => 'http://example.com/0', :status => 'new'}
@@ -15,19 +14,21 @@
h[4] = { :name => 'E: Bob task three', :region => 'us', :priority => 1, :url => 'http://example.com/3', :status => 'new'}
t.mput(h)
-# t.mget(0..3)
+
p "Fetch only new tasks"
-# q = t.query
-# q.condition('status', :streq, 'new')
-# q.limit(1)
-# p q.get
-# # => [{"name"=>"A: Joe task one", "region"=>"us", "priority"=>"2", "url"=>"http://example.com/0", "__id"=>"0", "status"=>"new"}]
+q = t.query
+ q.condition('status', :streq, 'new')
+ q.limit(1)
+p q.get
+# => [{"name"=>"A: Joe task one", "region"=>"us", "priority"=>"2", "url"=>"http://example.com/0", "__id"=>"0", "status"=>"new"}]
p "Changing to pending"
-p t.ext(:update_new_task, 1, 2)
+p t.ext(:update_new_task_2, 1, 2)
+p "all"
+pp t.mget(0..4)
-p "Fetch only new tasks order by priority"
+# p "Fetch only new tasks order by priority"
# q = t.query
# q.condition('status', :streq, 'new')
# q.order_by(:priority, :strasc)
@@ -35,10 +36,10 @@
# p q.get
# => [{"name"=>"D: Bob task two", "region"=>"eu", "priority"=>"1", "url"=>"http://example.com/3", "__id"=>"3", "status"=>"new"}]
-p "Changing to pending"
-p t.ext(:priority, 1, 2)
-
-p "Fetch only Bob's US new tasks"
+# p "Changing to pending"
+# p t.ext(:priority, 1, 2)
+#
+# p "Fetch only Bob's US new tasks"
# q = t.query
# q.condition('status', :streq, 'new')
# q.condition('region', :streq, 'us')
@@ -47,5 +48,5 @@
# p q.get
# => [{"name"=>"B: Bob task one", "region"=>"us", "priority"=>"2", "url"=>"http://example.com/1", "__id"=>"1", "status"=>"new"}]
-p "Changing to pending"
-p t.ext(:combo, 1, 2)
+# p "Changing to pending"
+# p t.ext(:combo, 1, 2)
View
42 wait-table/wait-table.lua
@@ -1,7 +1,36 @@
-- Equivalent to this sql
-- update table set status ="pending" where status = "new" limit 1
+-- const void *pkbuf, int pksiz, TCMAP *cols, void *op
+function pending(pkey, cols)
+ _log("at pending callback")
+ _log(pkey)
+ _log(cols)
+ local status = _misc("tcmapget2", cols, "status");
+ if not status then
+ _log("failed to get status", 2)
+ end
+
+ _misc("tcmapput2", cols, "status", "pending");
+ return TDBQPPUT;
+end
+
function update_new_task()
- -- body
+ _log("updating new task")
+ local args = {};
+ table.insert(args, "addcond\0status\0streq\0new")
+ table.insert(args, "setlimit\01")
+ table.insert(args, "columns")
+ _misc("proc", args, pending)
+
+ res = _misc("search", args)
+
+ if not res then
+ _log("failed misc", 2)
+ end
+ return res[1]
+end
+
+function update_new_task_2()
local args = {};
table.insert(args, "addcond\0status\0streq\0new")
table.insert(args, "setlimit\01")
@@ -13,11 +42,18 @@ function update_new_task()
for key,value in pairs(res) do
print(":"..tostring(key).."="..tostring(value)..":")
end
- -- The below is not working because re[1] is empty
- -- return _strstr(res[1], "new", "pending")
+ local new_value = return _strstr(res[1], "new", "pending")
+ _misc("putlist", new_value)
+
+ res = _misc("search", args)
+
+ if not res then
+ _log("failed misc", 2)
+ end
return res[1]
end
+
function priority()
-- body
local args = {};
Please sign in to comment.
Something went wrong with that request. Please try again.