durable_rules 0.34.23 → 0.34.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8768ac62052cef67e35af9093fe01f64f98e12a3
4
- data.tar.gz: 433d781a3bca977fd38ff976e676c57eb2e775dd
3
+ metadata.gz: 6a4ba28ab92f56567a70857c565e48bffc95e8b5
4
+ data.tar.gz: e1cbe2d01c35bcadd14084b78d1e96ec5037271c
5
5
  SHA512:
6
- metadata.gz: 4417b48ff669ba7b601b3dcbfdcf50a3e646f7a9808f27bf484068a493bcd919f34288cf9d3d3c727c28ef6ba6c2af3fb59662c9de9596db16fac5b8b18af2c1
7
- data.tar.gz: 9a28d775c90f4428349d23640e9825f66c73469c10dcfa5a8b040a1d20056d38ea2fac2ecd986ffbd748a7689ba127e43ca7c567daef1ffb975415c41eddaa2d
6
+ metadata.gz: e6606fba477f54cc6f76f8cd384aef942c5840ad206380af8c3b00e0edfb8101839278188063f622da768c4597c5be6e0a26e6ca379bcd44de21556eb644aa48
7
+ data.tar.gz: 6bfd931f12dc5e24b02f5227d9600c5b9b342d44485e1a47e5ed1a39b85c56fd21ebde19f24c4d075c968b1068ce7c7c153c089ff5e6922dca2c1c5372fb2911
data/src/rules/events.c CHANGED
@@ -46,7 +46,6 @@
46
46
  #define OP_NIL_NIL 0x0707
47
47
 
48
48
  typedef struct actionContext {
49
- unsigned long stateVersion;
50
49
  void *rulesBinding;
51
50
  redisReply *reply;
52
51
  } actionContext;
@@ -1052,14 +1051,15 @@ static unsigned int handleMessageCore(ruleset *tree,
1052
1051
  char **commands,
1053
1052
  unsigned int *commandCount,
1054
1053
  void **rulesBinding) {
1055
- jsonProperty *midProperty;
1054
+ jsonProperty *midProperty = NULL;
1056
1055
  int midLength;
1057
- jsonProperty *sidProperty;
1056
+ jsonProperty *sidProperty = NULL;
1058
1057
  int sidLength;
1059
1058
  char *storeCommand;
1060
- char *versionCommand;
1061
1059
  int result = getId(properties, sidIndex, &sidProperty, &sidLength);
1062
- if (result != RULES_OK) {
1060
+ if (result == ERR_NO_ID_DEFINED) {
1061
+ sidLength = 1;
1062
+ } else if (result != RULES_OK) {
1063
1063
  return result;
1064
1064
  }
1065
1065
  #ifdef _WIN32
@@ -1067,19 +1067,27 @@ static unsigned int handleMessageCore(ruleset *tree,
1067
1067
  #else
1068
1068
  char sid[sidLength + 1];
1069
1069
  #endif
1070
- strncpy(sid, message + sidProperty->valueOffset, sidLength);
1070
+ if (result == ERR_NO_ID_DEFINED) {
1071
+ *sid = '0';
1072
+ } else {
1073
+ strncpy(sid, message + sidProperty->valueOffset, sidLength);
1074
+ }
1071
1075
  sid[sidLength] = '\0';
1072
-
1076
+
1073
1077
  result = getId(properties, midIndex, &midProperty, &midLength);
1074
- if (result != RULES_OK) {
1078
+ if (result == ERR_NO_ID_DEFINED) {
1079
+ midLength = 0;
1080
+ } else if (result != RULES_OK) {
1075
1081
  return result;
1076
1082
  }
1077
1083
  #ifdef _WIN32
1078
1084
  char *mid = (char *)_alloca(sizeof(char)*(midLength + 1));
1079
1085
  #else
1080
1086
  char mid[midLength + 1];
1081
- #endif
1082
- strncpy(mid, message + midProperty->valueOffset, midLength);
1087
+ #endif
1088
+ if (midLength) {
1089
+ strncpy(mid, message + midProperty->valueOffset, midLength);
1090
+ }
1083
1091
  mid[midLength] = '\0';
1084
1092
  if (*commandCount == MAX_COMMAND_COUNT) {
1085
1093
  return ERR_MAX_COMMAND_COUNT;
@@ -1093,20 +1101,13 @@ static unsigned int handleMessageCore(ruleset *tree,
1093
1101
  }
1094
1102
  }
1095
1103
 
1096
- result = formatStoreSession(*rulesBinding, sid, state, 0, &storeCommand, &versionCommand);
1104
+ result = formatStoreSession(*rulesBinding, sid, state, 0, &storeCommand);
1097
1105
  if (result != RULES_OK) {
1098
1106
  return result;
1099
1107
  }
1100
1108
 
1101
1109
  commands[*commandCount] = storeCommand;
1102
1110
  ++*commandCount;
1103
-
1104
- if (*commandCount == MAX_COMMAND_COUNT) {
1105
- return ERR_MAX_COMMAND_COUNT;
1106
- }
1107
-
1108
- commands[*commandCount] = versionCommand;
1109
- ++*commandCount;
1110
1111
  }
1111
1112
  char *removeCommand = NULL;
1112
1113
  char *addKeys[MAX_ADD_COUNT];
@@ -1156,7 +1157,6 @@ static unsigned int handleMessageCore(ruleset *tree,
1156
1157
  addKeys,
1157
1158
  addCount,
1158
1159
  &addCommand);
1159
-
1160
1160
  for (unsigned int i = 0; i < addCount; ++i) {
1161
1161
  free(addKeys[i]);
1162
1162
  }
@@ -1185,6 +1185,7 @@ static unsigned int handleMessageCore(ruleset *tree,
1185
1185
  evalKeys,
1186
1186
  evalCount,
1187
1187
  &evalCommand);
1188
+
1188
1189
  for (unsigned int i = 0; i < evalCount; ++i) {
1189
1190
  free(evalKeys[i]);
1190
1191
  }
@@ -1224,23 +1225,21 @@ static unsigned int handleMessageCore(ruleset *tree,
1224
1225
  #ifdef _WIN32
1225
1226
  char *stateMessage = (char *)_alloca(sizeof(char)*(36 + sidLength));
1226
1227
  char *newState = (char *)_alloca(sizeof(char)*(12 + sidLength));
1227
- if (sidProperty->type == JSON_STRING) {
1228
- sprintf_s(stateMessage, sizeof(char)*(36 + sidLength), "{\"id\":\"$s\", \"sid\":\"%s\", \"$s\":1}", sid);
1228
+ if (sidProperty && sidProperty->type == JSON_STRING) {
1229
+ sprintf_s(stateMessage, sizeof(char)*(26 + sidLength), "{\"sid\":\"%s\", \"$s\":1}", sid);
1229
1230
  sprintf_s(newState, sizeof(char)*(12 + sidLength), "{\"sid\":\"%s\"}", sid);
1230
- }
1231
- else {
1232
- sprintf_s(stateMessage, sizeof(char)*(36 + sidLength), "{\"id\":\"$s\", \"sid\":%s, \"$s\":1}", sid);
1231
+ } else {
1232
+ sprintf_s(stateMessage, sizeof(char)*(26 + sidLength), "{\"sid\":%s, \"$s\":1}", sid);
1233
1233
  sprintf_s(newState, sizeof(char)*(12 + sidLength), "{\"sid\":%s}", sid);
1234
1234
  }
1235
1235
  #else
1236
1236
  char stateMessage[36 + sidLength];
1237
1237
  char newState[12 + sidLength];
1238
- if (sidProperty->type == JSON_STRING) {
1239
- snprintf(stateMessage, sizeof(char)*(36 + sidLength), "{\"id\":\"$s\", \"sid\":\"%s\", \"$s\":1}", sid);
1238
+ if (sidProperty && sidProperty->type == JSON_STRING) {
1239
+ snprintf(stateMessage, sizeof(char)*(26 + sidLength), "{\"sid\":\"%s\", \"$s\":1}", sid);
1240
1240
  snprintf(newState, sizeof(char)*(12 + sidLength), "{\"sid\":\"%s\"}", sid);
1241
- }
1242
- else {
1243
- snprintf(stateMessage, sizeof(char)*(36 + sidLength), "{\"id\":\"$s\", \"sid\":%s, \"$s\":1}", sid);
1241
+ } else {
1242
+ snprintf(stateMessage, sizeof(char)*(26 + sidLength), "{\"sid\":%s, \"$s\":1}", sid);
1244
1243
  snprintf(newState, sizeof(char)*(12 + sidLength), "{\"sid\":%s}", sid);
1245
1244
  }
1246
1245
  #endif
@@ -1249,21 +1248,13 @@ static unsigned int handleMessageCore(ruleset *tree,
1249
1248
  return ERR_MAX_COMMAND_COUNT;
1250
1249
  }
1251
1250
 
1252
- result = formatStoreSession(*rulesBinding, sid, newState, 1, &storeCommand, &versionCommand);
1251
+ result = formatStoreSession(*rulesBinding, sid, newState, 1, &storeCommand);
1253
1252
  if (result != RULES_OK) {
1254
1253
  return result;
1255
1254
  }
1256
1255
 
1257
1256
  commands[*commandCount] = storeCommand;
1258
1257
  ++*commandCount;
1259
-
1260
- if (*commandCount == MAX_COMMAND_COUNT) {
1261
- return ERR_MAX_COMMAND_COUNT;
1262
- }
1263
-
1264
- commands[*commandCount] = versionCommand;
1265
- ++*commandCount;
1266
-
1267
1258
  result = handleMessage(tree,
1268
1259
  NULL,
1269
1260
  stateMessage,
@@ -1399,7 +1390,6 @@ static unsigned int handleMessages(void *handle,
1399
1390
 
1400
1391
  static unsigned int handleState(ruleset *tree,
1401
1392
  char *state,
1402
- unsigned long stateVersion,
1403
1393
  char **commands,
1404
1394
  unsigned int *commandCount,
1405
1395
  void **rulesBinding) {
@@ -1414,15 +1404,15 @@ static unsigned int handleState(ruleset *tree,
1414
1404
 
1415
1405
  char *stateMessagePostfix = state + 1;
1416
1406
  #ifdef _WIN32
1417
- char *stateMessage = (char *)_alloca(sizeof(char)*(40 + stateLength - 1));
1407
+ char *stateMessage = (char *)_alloca(sizeof(char)*(24 + stateLength - 1));
1418
1408
  #else
1419
- char stateMessage[40 + stateLength - 1];
1409
+ char stateMessage[24 + stateLength - 1];
1420
1410
  #endif
1421
1411
 
1422
1412
  #ifdef _WIN32
1423
- sprintf_s(stateMessage, sizeof(char)*(40 + stateLength - 1), "{\"id\":\"$v-%016lu\", \"$s\":1, %s", stateVersion, stateMessagePostfix);
1413
+ sprintf_s(stateMessage, sizeof(char)*(24 + stateLength - 1), "{\"$s\":1, %s", stateMessagePostfix);
1424
1414
  #else
1425
- snprintf(stateMessage, sizeof(char)*(40 + stateLength - 1), "{\"id\":\"$v-%016lu\", \"$s\":1, %s", stateVersion, stateMessagePostfix);
1415
+ snprintf(stateMessage, sizeof(char)*(24 + stateLength - 1), "{\"$s\":1, %s", stateMessagePostfix);
1426
1416
  #endif
1427
1417
  unsigned int result = handleMessage(tree,
1428
1418
  state,
@@ -1679,18 +1669,12 @@ unsigned int assertState(void *handle, char *sid, char *state) {
1679
1669
  char *commands[MAX_COMMAND_COUNT];
1680
1670
  unsigned int commandCount = 0;
1681
1671
  void *rulesBinding = NULL;
1682
- unsigned long stateVersion;
1683
- unsigned int result = getStateVersion(handle, sid, &stateVersion);
1684
- if (result != RULES_OK) {
1685
- return result;
1686
- }
1687
1672
 
1688
- result = handleState(handle,
1689
- state,
1690
- stateVersion,
1691
- commands,
1692
- &commandCount,
1693
- &rulesBinding);
1673
+ unsigned int result = handleState(handle,
1674
+ state,
1675
+ commands,
1676
+ &commandCount,
1677
+ &rulesBinding);
1694
1678
  if (result != RULES_OK && result != ERR_EVENT_NOT_HANDLED) {
1695
1679
  freeCommands(commands, commandCount);
1696
1680
  return result;
@@ -1737,14 +1721,13 @@ unsigned int startAction(void *handle,
1737
1721
  return result;
1738
1722
  }
1739
1723
 
1740
- *state = reply->element[2]->str;
1741
- *messages = reply->element[3]->str;
1724
+ *state = reply->element[1]->str;
1725
+ *messages = reply->element[2]->str;
1742
1726
  actionContext *context = malloc(sizeof(actionContext));
1743
1727
  if (!context) {
1744
1728
  return ERR_OUT_OF_MEMORY;
1745
1729
  }
1746
1730
 
1747
- context->stateVersion = reply->element[1]->integer;
1748
1731
  context->reply = reply;
1749
1732
  context->rulesBinding = rulesBinding;
1750
1733
  *actionHandle = context;
@@ -1760,10 +1743,8 @@ unsigned int startUpdateState(void *handle,
1760
1743
  char *commands[MAX_COMMAND_COUNT];
1761
1744
  unsigned int result = RULES_OK;
1762
1745
  unsigned int commandCount = 0;
1763
- unsigned long stateVersion = ((actionContext*)actionHandle)->stateVersion;
1764
1746
  result = handleState(handle,
1765
- state,
1766
- stateVersion,
1747
+ state,
1767
1748
  commands,
1768
1749
  &commandCount,
1769
1750
  rulesBinding);
@@ -1798,7 +1779,6 @@ unsigned int completeAction(void *handle,
1798
1779
  ++commandCount;
1799
1780
  result = handleState(handle,
1800
1781
  state,
1801
- context->stateVersion,
1802
1782
  commands,
1803
1783
  &commandCount,
1804
1784
  &rulesBinding);
@@ -1871,8 +1851,7 @@ unsigned int completeAndStartAction(void *handle,
1871
1851
  return ERR_NO_ACTION_AVAILABLE;
1872
1852
  }
1873
1853
 
1874
- *messages = newReply->element[2]->str;
1875
- context->stateVersion = newReply->element[1]->integer;
1854
+ *messages = newReply->element[1]->str;
1876
1855
  context->reply = newReply;
1877
1856
  return RULES_OK;
1878
1857
  }
data/src/rules/net.c CHANGED
@@ -670,6 +670,7 @@ static unsigned int loadAddMessageCommand(ruleset *tree, binding *rulesBinding)
670
670
  "local events_hashset = \"%s!e!\" .. sid\n"
671
671
  "local facts_hashset = \"%s!f!\" .. sid\n"
672
672
  "local visited_hashset = \"%s!v!\" .. sid\n"
673
+ "local mid_count_hashset = \"%s!c\"\n"
673
674
  "local message = {}\n"
674
675
  "local primary_message_keys = {}\n"
675
676
  "local input_keys = {}\n"
@@ -696,14 +697,19 @@ static unsigned int loadAddMessageCommand(ruleset *tree, binding *rulesBinding)
696
697
  " end\n"
697
698
  "end\n"
698
699
  "local mid = message[\"id\"]\n"
699
- "if redis.call(\"hsetnx\", visited_hashset, message[\"id\"], 1) == 0 then\n"
700
- " if assert_fact == 0 then\n"
701
- " if not redis.call(\"hget\", events_hashset, mid) then\n"
702
- " return %d\n"
703
- " end\n"
704
- " else\n"
705
- " if not redis.call(\"hget\", facts_hashset, mid) then\n"
706
- " return %d\n"
700
+ "if not mid then\n"
701
+ " mid = \"$m-\" .. redis.call(\"hincrby\", mid_count_hashset, mid, 1)\n"
702
+ " message[\"id\"] = mid\n"
703
+ "else\n"
704
+ " if redis.call(\"hsetnx\", visited_hashset, mid, 1) == 0 then\n"
705
+ " if assert_fact == 0 then\n"
706
+ " if not redis.call(\"hget\", events_hashset, mid) then\n"
707
+ " return %d\n"
708
+ " end\n"
709
+ " else\n"
710
+ " if not redis.call(\"hget\", facts_hashset, mid) then\n"
711
+ " return %d\n"
712
+ " end\n"
707
713
  " end\n"
708
714
  " end\n"
709
715
  "end\n"
@@ -725,6 +731,7 @@ static unsigned int loadAddMessageCommand(ruleset *tree, binding *rulesBinding)
725
731
  name,
726
732
  name,
727
733
  name,
734
+ name,
728
735
  ERR_EVENT_OBSERVED,
729
736
  ERR_EVENT_OBSERVED,
730
737
  addMessageLua) == -1) {
@@ -1059,7 +1066,7 @@ static unsigned int loadPeekActionCommand(ruleset *tree, binding *rulesBinding)
1059
1066
  " end\n"
1060
1067
  " end\n"
1061
1068
  " for i = #packed_frames, 1, -1 do\n"
1062
- " redis.call(\"rpush\", rule_action_key, packed_frames[i])\n"
1069
+ " redis.call(\"lpush\", rule_action_key, packed_frames[i])\n"
1063
1070
  " end\n"
1064
1071
  " if #packed_frames == 0 then\n"
1065
1072
  " return nil, nil\n"
@@ -1189,12 +1196,11 @@ static unsigned int loadPeekActionCommand(ruleset *tree, binding *rulesBinding)
1189
1196
  "end\n"
1190
1197
  "if frame then\n"
1191
1198
  " redis.call(\"zadd\", action_key, tonumber(ARGV[1]), new_sid)\n"
1192
- " local state_version = redis.call(\"hget\", state_key .. \"!v\", new_sid)\n"
1193
1199
  " if #ARGV == 2 then\n"
1194
1200
  " local state = redis.call(\"hget\", state_key, new_sid)\n"
1195
- " return {new_sid, tonumber(state_version), state, cjson.encode({[action_name] = fixup_frame(frame)})}\n"
1201
+ " return {new_sid, state, cjson.encode({[action_name] = fixup_frame(frame)})}\n"
1196
1202
  " else\n"
1197
- " return {new_sid, tonumber(state_version), cjson.encode({[action_name] = fixup_frame(frame)})}\n"
1203
+ " return {new_sid, cjson.encode({[action_name] = fixup_frame(frame)})}\n"
1198
1204
  " end\n"
1199
1205
  "end\n",
1200
1206
  name,
@@ -1707,6 +1713,7 @@ static unsigned int loadEvalMessageCommand(ruleset *tree, binding *rulesBinding)
1707
1713
  "local visited_hashset = \"%s!v!\" .. sid\n"
1708
1714
  "local actions_key = \"%s!a\"\n"
1709
1715
  "local state_key = \"%s!s\"\n"
1716
+ "local mid_count_hashset = \"%s!c\"\n"
1710
1717
  "local queue_action = false\n"
1711
1718
  "local facts_message_cache = {}\n"
1712
1719
  "local events_message_cache = {}\n"
@@ -2143,14 +2150,21 @@ static unsigned int loadEvalMessageCommand(ruleset *tree, binding *rulesBinding)
2143
2150
  " message[\"$f\"] = 1\n"
2144
2151
  " end\n"
2145
2152
  "end\n"
2146
- "if redis.call(\"hsetnx\", visited_hashset, mid, 1) == 0 then\n"
2147
- " if assert_fact == 0 then\n"
2148
- " if message and redis.call(\"hexists\", events_hashset, mid) == 0 then\n"
2149
- " return %d\n"
2150
- " end\n"
2151
- " else\n"
2152
- " if message and redis.call(\"hexists\", facts_hashset, mid) == 0 then\n"
2153
- " return %d\n"
2153
+ "if mid == \"\" then\n"
2154
+ " mid = \"$m-\" .. redis.call(\"hincrby\", mid_count_hashset, sid, 1)\n"
2155
+ " if message then\n"
2156
+ " message[\"id\"] = mid\n"
2157
+ " end\n"
2158
+ "else\n"
2159
+ " if redis.call(\"hsetnx\", visited_hashset, mid, 1) == 0 then\n"
2160
+ " if assert_fact == 0 then\n"
2161
+ " if message and redis.call(\"hexists\", events_hashset, mid) == 0 then\n"
2162
+ " return %d\n"
2163
+ " end\n"
2164
+ " else\n"
2165
+ " if message and redis.call(\"hexists\", facts_hashset, mid) == 0 then\n"
2166
+ " return %d\n"
2167
+ " end\n"
2154
2168
  " end\n"
2155
2169
  " end\n"
2156
2170
  "end\n"
@@ -2163,12 +2177,12 @@ static unsigned int loadEvalMessageCommand(ruleset *tree, binding *rulesBinding)
2163
2177
  name,
2164
2178
  name,
2165
2179
  name,
2180
+ name,
2166
2181
  ERR_EVENT_OBSERVED,
2167
2182
  ERR_EVENT_OBSERVED,
2168
2183
  lua) == -1) {
2169
2184
  return ERR_OUT_OF_MEMORY;
2170
2185
  }
2171
-
2172
2186
  free(oldLua);
2173
2187
  unsigned int result = redisAppendCommand(reContext, "SCRIPT LOAD %s", lua);
2174
2188
  GET_REPLY(result, "loadEvalMessageCommand", reply);
@@ -2569,8 +2583,7 @@ unsigned int formatStoreSession(void *rulesBinding,
2569
2583
  char *sid,
2570
2584
  char *state,
2571
2585
  unsigned char tryExists,
2572
- char **storeCommand,
2573
- char **versionCommand) {
2586
+ char **storeCommand) {
2574
2587
  binding *currentBinding = (binding*)rulesBinding;
2575
2588
 
2576
2589
  int result;
@@ -2580,29 +2593,12 @@ unsigned int formatStoreSession(void *rulesBinding,
2580
2593
  currentBinding->sessionHashset,
2581
2594
  sid,
2582
2595
  state);
2583
- if (result == 0) {
2584
- return ERR_OUT_OF_MEMORY;
2585
- }
2586
-
2587
- result = redisFormatCommand(versionCommand,
2588
- "hsetnx %s!v %s 0",
2589
- currentBinding->sessionHashset,
2590
- sid);
2591
2596
  } else {
2592
2597
  result = redisFormatCommand(storeCommand,
2593
2598
  "hset %s %s %s",
2594
2599
  currentBinding->sessionHashset,
2595
2600
  sid,
2596
2601
  state);
2597
-
2598
- if (result == 0) {
2599
- return ERR_OUT_OF_MEMORY;
2600
- }
2601
-
2602
- result = redisFormatCommand(versionCommand,
2603
- "hincrby %s!v %s 1",
2604
- currentBinding->sessionHashset,
2605
- sid);
2606
2602
  }
2607
2603
 
2608
2604
  if (result == 0) {
@@ -2894,7 +2890,7 @@ unsigned int peekAction(ruleset *tree, void **bindingContext, redisReply **reply
2894
2890
  }
2895
2891
 
2896
2892
  if ((*reply)->type == REDIS_REPLY_ARRAY) {
2897
- if ((*reply)->elements < 4) {
2893
+ if ((*reply)->elements < 3) {
2898
2894
  freeReplyObject(*reply);
2899
2895
  return ERR_REDIS_ERROR;
2900
2896
  }
data/src/rules/net.h CHANGED
@@ -74,8 +74,7 @@ unsigned int formatStoreSession(void *rulesBinding,
74
74
  char *sid,
75
75
  char *state,
76
76
  unsigned char tryExists,
77
- char **storeCommand,
78
- char **versionCommand);
77
+ char **storeCommand);
79
78
 
80
79
  unsigned int formatStoreSessionFact(void *rulesBinding,
81
80
  char *sid,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: durable_rules
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.34.23
4
+ version: 0.34.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesus Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-05 00:00:00.000000000 Z
11
+ date: 2017-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake