Skip to content

Commit

Permalink
get_cursor to support readable time
Browse files Browse the repository at this point in the history
  • Loading branch information
wjo1212 committed Jan 23, 2018
1 parent 34a814e commit 4b6debf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions aliyun/log/logclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,15 +476,15 @@ def get_cursor(self, project_name, logstore_name, shard_id, start_time):
:param shard_id: the shard id
:type start_time: string/int
:param start_time: the start time of cursor, e.g 1441093445 or "begin"/"end"
:param start_time: the start time of cursor, e.g 1441093445 or "begin"/"end", or "%Y-%m-%d %H:%M:%S"
:return: GetCursorResponse
:raise: LogException
"""

headers = {'Content-Type': 'application/json'}
params = {'type': 'cursor', 'from': str(start_time)}
params = {'type': 'cursor', 'from': str(start_time) if start_time in ("begin", "end") else parse_timestamp(start_time)}

resource = "/logstores/" + logstore_name + "/shards/" + str(shard_id)
(resp, header) = self._send("GET", project_name, None, resource, params, headers)
Expand Down
7 changes: 7 additions & 0 deletions tests/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def sample_put_logs(client, project, logstore, compress=False):
res = client.get_previous_cursor_time(project, logstore, 0, end_cursor)
res.log_print()


# @log_enter_exit
def sample_pull_logs(client, project, logstore, compress=False):
res = client.get_cursor(project, logstore, 0, int(time.time() - 60))
Expand All @@ -47,6 +48,12 @@ def sample_pull_logs(client, project, logstore, compress=False):
res = client.pull_logs(project, logstore, 0, cursor, 1, compress=compress)
res.log_print()

# test readable start time
res = client.get_cursor(project, logstore, 0,
datetime.fromtimestamp(int(time.time() - 60)).strftime('%Y-%m-%d %H:%M:%S'))
res.log_print()


# @log_enter_exit
def sample_list_logstores(client, project):
request = ListLogstoresRequest(project)
Expand Down

0 comments on commit 4b6debf

Please sign in to comment.