-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_redis.py
62 lines (41 loc) · 1.79 KB
/
test_redis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from redis import Redis
from rq import Queue
import datetime
import pytz
import random
from redis_functions.redis_updater import update_db
redis_connection_local = Redis(host="pearlfish.redistogo.com", port=10453,
password="6b7025eac8f3f18072d7496c96d8e8c5", username="redistogo")
q = Queue('test_queue', connection=redis_connection_local)
# class Time:
# def __init__(self):
# self.last_time = datetime.datetime.now(
# tz=pytz.timezone('Asia/Kolkata'))
# def get_time(self):
# random_seconds = random.randint(1, 5)
# print("Random seconds: ", random_seconds)
# Timedelta = datetime.timedelta(seconds=random_seconds)
# new_time = self.last_time + Timedelta
# self.last_time = new_time
# print("Job scheduled at: ", new_time)
# return new_time
# enqueue 10 jobs to run at time intervals of 1 minute
present_time = datetime.datetime.now(tz=pytz.timezone('Asia/Kolkata'))
for i in range(0, 10):
new_time = present_time + datetime.timedelta(minutes=1)
present_time = new_time
job = q.enqueue_at(new_time, update_db)
print(job)
# naive datetime
# timef = datetime.datetime.combine(datetime.date.today(), datetime.time(12, 11))
# timea = datetime.datetime.combine(datetime.date.today(), datetime.time(12, 12))
# timezone_awaredatetime
# timezone_india = pytz.timezone('Asia/Kolkata')
# time = datetime.time(12, 30)
# date_time = datetime.datetime.now(timezone)
# timedelta = datetime.timedelta(seconds=random_seconds)
# dt = date_time + timedelta
# this is a naive datetime, convert it to timezone aware datetime
# new_dt = timezone_india.localize(dt)
# joba = q.enqueue_at(time.get_time(), amazon, amazon_productid)
# jobf = q.enqueue_at(time.get_time(), flipkart, flipkart_productid)