Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sdo-grading-job-snatcher
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shared
sdo-grading-job-snatcher
Commits
37c8f923
Commit
37c8f923
authored
Oct 08, 2025
by
Fredrik Wendt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use count down latch to decide whether to snatch work
parent
7b14ae10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
11 deletions
+15
-11
snatcher.py
snatcher.py
+5
-1
wrapper.py
wrapper.py
+10
-10
No files found.
snatcher.py
View file @
37c8f923
...
@@ -14,8 +14,9 @@ load_dotenv()
...
@@ -14,8 +14,9 @@ load_dotenv()
login_user
=
os
.
environ
[
'LOGIN_USER'
]
login_user
=
os
.
environ
[
'LOGIN_USER'
]
login_pass
=
os
.
environ
[
'LOGIN_PASS'
]
login_pass
=
os
.
environ
[
'LOGIN_PASS'
]
def
snatch_grading_work
(
headless
=
None
):
def
snatch_grading_work
(
headless
=
None
)
->
bool
:
global
log
global
log
work_snatched
=
False
if
log
is
None
:
if
log
is
None
:
log
=
logging
.
getLogger
(
'snatcher'
)
log
=
logging
.
getLogger
(
'snatcher'
)
...
@@ -74,6 +75,7 @@ def snatch_grading_work(headless=None):
...
@@ -74,6 +75,7 @@ def snatch_grading_work(headless=None):
while
True
:
while
True
:
current_buttons
=
page
.
query_selector_all
(
'span:text-is("Claim")'
)
current_buttons
=
page
.
query_selector_all
(
'span:text-is("Claim")'
)
if
len
(
current_buttons
)
==
claim_count
-
1
:
if
len
(
current_buttons
)
==
claim_count
-
1
:
work_snatched
=
True
break
break
if
time
.
time
()
-
start_time
>
30
:
# Timeout after 30 seconds
if
time
.
time
()
-
start_time
>
30
:
# Timeout after 30 seconds
break
break
...
@@ -91,6 +93,8 @@ def snatch_grading_work(headless=None):
...
@@ -91,6 +93,8 @@ def snatch_grading_work(headless=None):
playwright
.
stop
()
playwright
.
stop
()
log
.
info
(
"Done snatching grading work"
)
log
.
info
(
"Done snatching grading work"
)
return
work_snatched
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
logging
.
basicConfig
(
level
=
logging
.
INFO
,
stream
=
sys
.
stdout
)
logging
.
basicConfig
(
level
=
logging
.
INFO
,
stream
=
sys
.
stdout
)
...
...
wrapper.py
View file @
37c8f923
...
@@ -13,7 +13,7 @@ development_mode = os.getenv('PYCHARM_HOSTED')
...
@@ -13,7 +13,7 @@ development_mode = os.getenv('PYCHARM_HOSTED')
def
main
():
def
main
():
log
=
logging
.
getLogger
(
'wrapper'
)
log
=
logging
.
getLogger
(
'wrapper'
)
messages_seen
=
[]
wait_n_messages_before_snatching
=
0
log
.
info
(
"Running main"
)
log
.
info
(
"Running main"
)
host
=
'localhost'
if
development_mode
else
'redis.wendt.vpn'
host
=
'localhost'
if
development_mode
else
'redis.wendt.vpn'
...
@@ -25,7 +25,7 @@ def main():
...
@@ -25,7 +25,7 @@ def main():
while
True
:
while
True
:
now
=
datetime
.
datetime
.
now
(
datetime
.
timezone
.
utc
)
.
isoformat
(
sep
=
' '
,
timespec
=
'seconds'
)
now
=
datetime
.
datetime
.
now
(
datetime
.
timezone
.
utc
)
.
isoformat
(
sep
=
' '
,
timespec
=
'seconds'
)
log
.
info
(
f
"
Starting to wait for message
at {now}"
)
log
.
info
(
f
"
Waiting for messages ({wait_n_messages_before_snatching})
at {now}"
)
try
:
try
:
message
=
pubsub
.
get_message
(
ignore_subscribe_messages
=
True
,
timeout
=
60.0
)
message
=
pubsub
.
get_message
(
ignore_subscribe_messages
=
True
,
timeout
=
60.0
)
if
message
:
if
message
:
...
@@ -42,15 +42,15 @@ def main():
...
@@ -42,15 +42,15 @@ def main():
subject
=
data
[
"headers"
][
"subject"
]
subject
=
data
[
"headers"
][
"subject"
]
log
.
info
(
f
"Subject: {subject}"
)
log
.
info
(
f
"Subject: {subject}"
)
if
"III Grading Required"
in
subject
:
if
"III Grading Required"
in
subject
:
if
len
(
messages_seen
)
==
0
:
log
.
info
(
"Subject found - let's consider snatching!"
)
log
.
info
(
"Subject found - let's go snatching!"
)
if
wait_n_messages_before_snatching
<=
0
:
snatch_grading_work
()
log
.
info
(
"Yes, it's our time to shine - go go go!"
)
if
snatch_grading_work
():
log
.
info
(
"Got new work, resetting wait to 4"
)
wait_n_messages_before_snatching
=
4
else
:
else
:
log
.
info
(
"Not snatching this one, only every 4th"
)
wait_n_messages_before_snatching
=-
1
messages_seen
.
append
(
message
)
log
.
info
(
f
"Not snatching this one, awaiting another {wait_n_messages_before_snatching} messages before snatching"
)
if
len
(
messages_seen
)
==
4
:
log
.
info
(
"Clearing message log, snatching the next one"
)
messages_seen
=
[]
else
:
else
:
log
.
info
(
"Ignoring this email"
)
log
.
info
(
"Ignoring this email"
)
except
Exception
as
e
:
except
Exception
as
e
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment