Skip to content

This is my way python example which requests events history or consumes queue with fetching its position id in local file.

Notifications You must be signed in to change notification settings

noexpect/request_fetcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

request_fetcher

This is my way python example which requests events history or consumes queue with position id in local file.

Assumed use case & Implements

When you fetch the events history via http api, flequently you will see such as following json response.


{
  "log_entries": [
    {
      "id": "XXXXXXX",
      "type": "a",
      "summary": "aa",
      "time": "2017-01-02T03:04:05",
      ...
    },
    {
      "id": "YYYYYYYY",
      "type": "b",
      "summary": "bb",
      "time":"2017-02-02T03:04:05",
      ...
    },
    ...
}

In this case, you need to keep the state for remembering where you have scaped.

So this code will save the state as pickle dump file in your local storage. (This is casual way. As you know, saving the state in remote storage is better.)

Run & Result

$ python -V
Python 3.6.0

# first time
$ python request_fetcher.py

previous state not found. So initialized.
saved state: {'position_id': 0}
do something with pickled state:  {'position_id': 0}
saved state: {'position_id': 1}

# position.dump was generated.
$ ll
total 9
-rw-r--r-- 1 hoge 197609   27 6月   4 04:03 position.dump
-rw-r--r-- 1 hoge 197609 1015 6月   4 04:04 README.md
-rw-r--r-- 1 hoge 197609 1284 6月   4 03:23 request_fetcher.py

# second time
$ python request_fetcher.py

pickled file found
previous state: {'position_id': 1}
do something with pickled state:  {'position_id': 1}
saved state: {'position_id': 2}
# position_id was updated.


About

This is my way python example which requests events history or consumes queue with fetching its position id in local file.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages