You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

lua_script.py 3.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # !/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. """
  4. Copyright 2020 Tianshu AI Platform. All Rights Reserved.
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================
  15. """
  16. getTaskLua = """
  17. local namespace = KEYS[1]
  18. local pre_task_queue_name = "pre_task"
  19. local detail_task_queue_name = "detail"
  20. local processing_task_queue_name = "processing"
  21. local pre_task_queue = redis.call("get", namespace..":"..pre_task_queue_name)
  22. local time = redis.call('TIME')
  23. local time_reset = (time[1]*1000000+time[2])/1000
  24. local current_task_queue
  25. local keys = redis.call("keys",namespace..":*:*:task:*")
  26. -- 定义分割字符串函数
  27. local __split
  28. function __split(str, reps)
  29. local r = {}
  30. if (str == nil) then
  31. return nil
  32. end
  33. string.gsub(str, "[^"..reps.."]+", function(w) table.insert(r,w) end)
  34. return r
  35. end
  36. -- 定义分割字符串函数
  37. if (pre_task_queue == false and #keys > 0) then
  38. redis.call("set", namespace..":"..pre_task_queue_name, 1)
  39. current_task_queue = keys[1]
  40. else
  41. for i=1,#keys,1
  42. do
  43. if i == pre_task_queue then
  44. if i < #keys then
  45. redis.call("set", namespace..":"..pre_task_queue_name, i+1)
  46. current_task_queue = keys[i+1]
  47. else
  48. redis.call("set", namespace..":"..pre_task_queue_name, 1)
  49. current_task_queue = keys[1]
  50. end
  51. end
  52. end
  53. end
  54. if (pre_task_queue ~= false and #keys > 0 and current_task_queue == nil) then
  55. redis.call("set", namespace..":"..pre_task_queue_name, 1)
  56. current_task_queue = keys[1]
  57. end
  58. if current_task_queue == nil then
  59. return nil
  60. else
  61. local element = redis.call('zrangebyscore', current_task_queue, 0, 9999999999999, 'limit', 0, 1)
  62. redis.call("zrem", current_task_queue, element[1])
  63. element = string.gsub(element[1], "\\"", "")
  64. redis.call("zadd", KEYS[1]..":"..__split(current_task_queue, ":")[3]..":"..__split(current_task_queue, ":")[4]..":"..processing_task_queue_name..":"..__split(current_task_queue, ":")[6], time_reset, element)
  65. return KEYS[1]..":"..__split(current_task_queue, ":")[3]..":"..__split(current_task_queue, ":")[4]..":"..detail_task_queue_name..":"..element
  66. end
  67. """
  68. saveTaskLua= """
  69. local __split
  70. function __split(str, reps)
  71. local r = {}
  72. if (str == nil) then
  73. return nil
  74. end
  75. string.gsub(str, "[^"..reps.."]+", function(w) table.insert(r,w) end)
  76. return r
  77. end
  78. -- 定义分割字符串函数
  79. local str_sub = __split(KEYS[1], ":")
  80. local processing_task_queue_name = str_sub[1]..":"..str_sub[2]..":"..str_sub[3]..":"..str_sub[4]..":".."processing"..":001"
  81. local finished_task_queue_name = str_sub[1]..":"..str_sub[2]..":"..str_sub[3]..":"..str_sub[4]..":".."finished"..":"..str_sub[6]
  82. local annotation = str_sub[1]..":"..str_sub[2]..":"..str_sub[3]..":"..str_sub[4]..":".."annotation"..":"..str_sub[6]
  83. redis.call("zrem", processing_task_queue_name, str_sub[6])
  84. redis.call("zadd", finished_task_queue_name, 1, annotation)
  85. redis.call("set", annotation, KEYS[2])
  86. return annotation
  87. """

一站式算法开发平台、高性能分布式深度学习框架、先进算法模型库、视觉模型炼知平台、数据可视化分析平台等一系列平台及工具,在模型高效分布式训练、数据处理和可视分析、模型炼知和轻量化等技术上形成独特优势,目前已在产学研等各领域近千家单位及个人提供AI应用赋能