Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added support for delay and expires_in parameters

  • Loading branch information...
commit 0898536879f3dc950d636fd173c758cd8fed443f 1 parent ca874ff
Thejo Kote authored
2  .gitignore
View
@@ -1,2 +1,4 @@
reports
target
+.idea
+*.iml
36 src/main/java/io/iron/ironmq/Message.java
View
@@ -9,6 +9,10 @@
private String id;
private String body;
private long timeout;
+ private long delay;
+ private long expires_in;
Evan Shaw
edsrzf added a note

I would rather conform to Java conventions than our API conventions. Please rename this to expiresIn.

Thejo Kote Owner
thejo added a note

The JSON serializer will use "expiresIn" as the parameter, but your API expects "expires_in". That's why I broke Java convention and named the variable expires_in. Does your REST API accept expiresIn as the parameter? I can change it if it does.

Evan Shaw
edsrzf added a note

Ah, I see, that would be invalid. I suppose it's alright to keep this name for the private variable but change the mutator and accessor. I'll probably have to rework how serialization is done at some point anyway.

Thejo Kote Owner
thejo added a note

That was how I had implemented it. It looks like the getter and setter names are used in the serialization. I had to rename them to get the correct JSON format. You can try it.

Evan Shaw
edsrzf added a note

Ok, I'll have a play with it. What a hassle (but not your fault at all).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ public static final long DEFAULT_EXPIRES_IN = 604800;
public Message() {}
@@ -49,6 +53,38 @@ public Message() {}
public void setTimeout(long timeout) { this.timeout = timeout; }
/**
+ * Returns the Message's delay.
+ */
+ public long getDelay() {
+ return delay;
+ }
+
+ /**
+ * Sets the number of seconds after which the Message will be available
+ *
+ * @param delay The new delay
+ */
+ public void setDelay(long delay) {
+ this.delay = delay;
+ }
+
+ /**
+ * Returns the number of seconds in which this message will be removed from the queue
+ */
+ public long getExpires_in() {
Evan Shaw
edsrzf added a note

As above, please rename this to getExpiresIn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return expires_in;
+ }
+
+ /**
+ * Sets the number of seconds after which the message is deleted from the queue.
+ *
+ * @param expires_in The new expiry value
+ */
+ public void setExpires_in(long expires_in) {
Evan Shaw
edsrzf added a note

Please rename to setExpiresIn and the argument to expiresIn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ this.expires_in = expires_in;
+ }
+
+ /**
* Returns a string representation of the Message.
*/
public String toString() { return body; }
14 src/main/java/io/iron/ironmq/Queue.java
View
@@ -82,7 +82,15 @@ public void deleteMessage(Message msg) throws IOException {
* @throws IOException If there is an error accessing the IronMQ server.
*/
public void push(String msg) throws IOException {
- push(msg, 0);
+ push(msg, 0, 0, Message.DEFAULT_EXPIRES_IN);
+ }
+
+ public void push(String msg, long timeout) throws IOException {
+ push(msg, timeout, 0, Message.DEFAULT_EXPIRES_IN);
+ }
+
+ public void push(String msg, long timeout, long delay) throws IOException {
+ push(msg, timeout, delay, Message.DEFAULT_EXPIRES_IN);
}
/**
@@ -94,10 +102,12 @@ public void push(String msg) throws IOException {
* @throws HTTPException If the IronMQ service returns a status other than 200 OK.
* @throws IOException If there is an error accessing the IronMQ server.
*/
- public void push(String msg, long timeout) throws IOException {
+ public void push(String msg, long timeout, long delay, long expiresIn) throws IOException {
Message message = new Message();
message.setBody(msg);
message.setTimeout(timeout);
+ message.setDelay(delay);
+ message.setExpires_in(expiresIn);
JSON jsonMsg = JSONSerializer.toJSON(message);
JSONArray array = new JSONArray();

2 comments on commit 0898536

Evan Shaw

I would rather conform to Java conventions than our API conventions. Please rename this to expiresIn.

Evan Shaw

As above, please rename this to getExpiresIn

Evan Shaw

Please rename to setExpiresIn and the argument to expiresIn

Evan Shaw

Thanks! This looks pretty good overall.

I made some comments inline. You can address them yourself or I can just fix them if you like. Either way's fine with me.

Thejo Kote

The JSON serializer will use "expiresIn" as the parameter, but your API expects "expires_in". That's why I broke Java convention and named the variable expires_in. Does your REST API accept expiresIn as the parameter? I can change it if it does.

Thejo Kote
Owner

Can you confirm that using "expiresIn" in the JSON POSTed to your REST API valid.

Evan Shaw

Ah, I see, that would be invalid. I suppose it's alright to keep this name for the private variable but change the mutator and accessor. I'll probably have to rework how serialization is done at some point anyway.

Thejo Kote

That was how I had implemented it. It looks like the getter and setter names are used in the serialization. I had to rename them to get the correct JSON format. You can try it.

Evan Shaw

Ok, I'll have a play with it. What a hassle (but not your fault at all).

Please sign in to comment.
Something went wrong with that request. Please try again.