File tree 1 file changed +8
-0
lines changed
1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ namespace ImgBot.Function
11
11
{
12
12
public static class Functions
13
13
{
14
+ private static Random s_random = new Random ( ) ;
15
+
14
16
[ FunctionName ( "imageupdatemessage" ) ]
15
17
public static async Task RunImageUpdateMessage (
16
18
[ QueueTrigger ( "imageupdatemessage" ) ] ImageUpdateMessage imageUpdateMessage ,
@@ -84,6 +86,12 @@ public static async Task RunInstallationMessage(
84
86
RepoOwner = installationMessage . Owner ,
85
87
} ;
86
88
89
+ // getting duplicate work happening at the same exact time in multiple threads
90
+ // the most common case is install and add events on the same repo when the queue is asleep
91
+ // the queue wakes up and dequeues both messages at the same time in 2 threads
92
+ // wait a random amount of seconds so that one will win
93
+ System . Threading . Thread . Sleep ( TimeSpan . FromSeconds ( s_random . Next ( 0 , 20 ) ) ) ;
94
+
87
95
await CompressImages . RunAsync ( compressImagesParameters ) ;
88
96
}
89
97
}
You can’t perform that action at this time.
0 commit comments