Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a task tracking script #14

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Catalog Scripts

This is a script that shows the `n` most up-to-date tasks

## Setup

In an apt-based Linux distro, type the below commands to install the script dependency:

```.bash
wget http://initd.org/psycopg/tarballs/PSYCOPG-2-6/psycopg2-2.6.tar.gz
tar -vzxf psycopg2-2.6.tar.gz
cd psycopg2-2.6
python3 setup.py install
sudo apt-get install python3-psycopg2
```

## How to use

```.bash
./catalog.py <catalog_address> <catalog_port> <catalog_db_name> <catalog_user_name> <catalog_user_password>
```

By default it will show the 10 most up-to-date tasks, but you can also specify the number of tasks to show:

```.bash
./catalog.py <catalog_address> <catalog_port> <catalog_db_name> <catalog_user_name> <catalog_user_password> -n <Number of tasks to show>
```
61 changes: 61 additions & 0 deletions scripts/catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/python3

import psycopg2
import json
import argparse

def parseArguments():
parser = argparse.ArgumentParser()

parser.add_argument("catalog_address", help="Catalog Address", type=str)
parser.add_argument("catalog_port", help="Catalog Port", type=str)
parser.add_argument("catalog_db_name", help="Catalog Database Name", type=str)
parser.add_argument("catalog_user_name", help="Catalog user",type=str)
parser.add_argument("catalog_user_password", help="Catalog Password",type=str)

#Optional Argument
parser.add_argument("-n", "--number", help="Number of tasks to show", type=int, default=10)

args = parser.parse_args()
return args

def result_to_dic(query_result):
result = str(query_result)[2:-3].replace("\'", "\"")

tasks = json.loads(result)
return tasks


def getTasks(mydb,total = 10):

mycursor = mydb.cursor()

query = "select json_agg(t) from (select * from tasks order by updated_time desc FETCH first " + str(total) + " rows only) t"

# Get list of tasks sorted by updateTime
mycursor.execute(query)

query_result = mycursor.fetchall()

tasks = result_to_dic(query_result)


print("taskId | dataset | region | imageDate | state")

for i in range(total):
task = tasks[i]
print(task['task_id'] + " | " + task['dataset'] + " | " + task['region'] + " | " + task['image_date'] + " | " + task['state'])

if __name__ == '__main__':
# Parse the arguments
args = parseArguments()

mydb = psycopg2.connect(
host=args.catalog_address,
user=args.catalog_user_name,
password=args.catalog_user_password,
database=args.catalog_db_name,
port=args.catalog_port
)

getTasks(mydb,args.number)