| 23 | } |
| 24 | |
| 25 | bool disque_job::init(const redis_result& rr) |
| 26 | { |
| 27 | size_t n; |
| 28 | const redis_result** children = rr.get_children(&n); |
| 29 | if (n == 0) { |
| 30 | return false; |
| 31 | } |
| 32 | if (n % 2 != 0) { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | string name; |
| 37 | for (size_t i = 0; i < n;) { |
| 38 | const redis_result* r1 = children[i]; |
| 39 | i++; |
| 40 | const redis_result* r2 = children[i]; |
| 41 | i++; |
| 42 | if (r1->get_type() != REDIS_RESULT_STRING) { |
| 43 | continue; |
| 44 | } |
| 45 | name.clear(); |
| 46 | r1->argv_to_string(name); |
| 47 | if (name.empty()) { |
| 48 | continue; |
| 49 | } |
| 50 | |
| 51 | redis_result_t type = r2->get_type(); |
| 52 | |
| 53 | #define EQ(x, y) !strcasecmp((x).c_str(), (y)) |
| 54 | #define IS_NUMBER(x) (x) == REDIS_RESULT_INTEGER |
| 55 | #define IS_STRING(x) (x) == REDIS_RESULT_STRING |
| 56 | #define IS_ARRAY(x) (x) == REDIS_RESULT_ARRAY |
| 57 | |
| 58 | if (EQ(name, "id") && IS_STRING(type)) { |
| 59 | r2->argv_to_string(id_); |
| 60 | } else if (EQ(name, "queue") && IS_STRING(type)) { |
| 61 | r2->argv_to_string(queue_); |
| 62 | } else if (EQ(name, "state") && IS_STRING(type)) { |
| 63 | r2->argv_to_string(state_); |
| 64 | } else if (EQ(name, "repl") && IS_NUMBER(type)) { |
| 65 | repl_ = r2->get_integer(); |
| 66 | } else if (EQ(name, "ttl") && IS_NUMBER(type)) { |
| 67 | ttl_ = r2->get_integer(); |
| 68 | } else if (EQ(name, "ctime") && IS_NUMBER(type)) { |
| 69 | ctime_ = r2->get_integer64(); |
| 70 | } else if (EQ(name, "delay") && IS_NUMBER(type)) { |
| 71 | delay_ = r2->get_integer(); |
| 72 | } else if (EQ(name, "retry") && IS_NUMBER(type)) { |
| 73 | retry_ = r2->get_integer(); |
| 74 | } else if (EQ(name, "nodes-delivered") && IS_ARRAY(type)) { |
| 75 | set_nodes_delivered(*r2); |
| 76 | } else if (EQ(name, "nodes-confirmed") && IS_ARRAY(type)) { |
| 77 | set_nodes_confirmed(*r2); |
| 78 | } else if (EQ(name, "next-requeue-within") && IS_NUMBER(type)) { |
| 79 | next_requeue_within_ = r2->get_integer(); |
| 80 | } else if (EQ(name, "next-awake-within") && IS_NUMBER(type)) { |
| 81 | next_awake_within_ = r2->get_integer(); |
| 82 | } else if (EQ(name, "body") && IS_STRING(type)) { |
no test coverage detected