Skip to content

Commit

Permalink
Don't use accounts for disabled workers
Browse files Browse the repository at this point in the history
  • Loading branch information
modrzew committed Aug 17, 2016
1 parent 0938ed3 commit f61ba40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,21 @@ def sort_points_for_worker(points, worker_no):

def get_distance(p1, p2):
return math.sqrt(pow(p1[0] - p2[0], 2) + pow(p1[1] - p2[1], 2))


def get_worker_account(worker_no):
"""Returns appropriate ACCOUNT entry for worker
Omits disabled workers.
"""
# This should never happen, but better be safe!
if worker_no in config.DISABLE_WORKERS:
return None, None, None
account_no = 0
for i in range(worker_no + 1):
if i in config.DISABLE_WORKERS:
continue
if i == worker_no:
return config.ACCOUNTS[account_no]
account_no += 1
raise ValueError('Workers incompatible with accounts')
5 changes: 3 additions & 2 deletions worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ def run(self):
self.cycle = 1
self.error_code = None

username, password, service = utils.get_worker_account(self.worker_no)
service = config.ACCOUNTS[self.worker_no][2]
while True:
try:
loginsuccess = self.api.login(
username=username,
password=password,
provider=service,
username=config.ACCOUNTS[self.worker_no][0],
password=config.ACCOUNTS[self.worker_no][1],
)
if not loginsuccess:
self.error_code = 'LOGIN FAIL'
Expand Down

2 comments on commit f61ba40

@YonderGod
Copy link

@YonderGod YonderGod commented on f61ba40 Aug 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't line 101 be removed since service already defined in the line above it?
This is great, btw, I had no idea how to do it.

Yes, it seems that was causing the number of threads to continuously go up. For my own curiosity, can you explain why it did that? I don't get it.

Edit: I have no idea what I'm talking about. See issue #248

@modrzew
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that line should be removed. Fixed in 37e82c7.

Please sign in to comment.