Probability and time This is a real-world problem, but I've simplified the numbers for convenience.
A system upgrade takes $500$ minutes. During a system upgrade, the database will be unavailable for $2$ minutes.
There's a task that takes $0.5$ minutes and needs the database during the entire $0.5$ minutes or it will fail.
If I run the task during a system upgrade, what is the probability that it will fail because the database is unavailable? 

What I've tried:
Prob that DB is unavailable during a given minute, during the upgrade = $\frac{2}{500}$ $= 0.004$
Prob of task failing $= 0.5*0.004 = 0.002$
But that doesn't seem right because if the task instead took $500$ minutes, the probability of failure should be $1$, yet the calculation gives $2$

Picking up at step 4 of Semoi's answer, I get a different result when applying Bayes' rule.
$P(\textrm{fail} | t\le u) = P(u\le t+0.5 | t\le u) = \frac{P(t\le u | u\le t+0.5)P(u\le t+0.5)}{P(t\le u)}$
But
$P(t\le u | u\le t+0.5) = \frac{P(t\le u \cap u\le t+0.5)}{P(u\le t+0.5)} = \frac{P(t\le u\le t+0.5)}{P(u\le t+0.5)}$
So 
$P(\textrm{fail} | t\le u) = \frac{P(t\le u\le t+0.5)}{P(t\le u)}$
Similarly
$P(\textrm{fail} | t \ge u) = \frac{P(u\le t \le u+2)}{P(t\ge u)}$
then
$P(\textrm{fail}) = P(t\le u\le t+0.5) + P(u\le t \le u+2)$
Which, in hindsight, seems logical to me. I.e., it fails if either the database becomes available in the middle of the task, or the task starts while the database is unavailable. Or have I gone off-track?
 A: To think through questions like this, draw a picture.
To answer such questions, draw the picture!

The question
Let's be clear about the interpretation:

*

*"Run the task during a system upgrade" means you will start the task during an interval known to be a system upgrade.


*"The database will be unavailable for 2 minutes" means that at some unpredictable time during the upgrade, there will be a continuous two-minute interval of unavailable falling entirely during the upgrade period.
Let $x$ be the start of the task.  Evidently $0 \le x \lt 500$.
Let $y$ be the start of the unavailability.  Evidently $0 \le y \le 500-2$.
There are many ways to interpret "unpredictable time." To illustrate, suppose this means the database outage is known to have the same chance of starting at any one of the possible times: it has a uniform distribution.
Similarly, there are many ways to model what it means to run the task during a system upgrade, and one of those is to suppose that every time during the upgrade has an equal chance of being when the task is run.
(These assumptions can be made more complicated, but they amount to defining a probability distribution on the set of all combinations of a relevant task start $x$ and database outage start $y$.  The same pictures shown below will continue to be useful at ensuring you compute the correct integrals over those distributions.)

A solution
Failure occurs when the task overlaps the database outage period.  This is easiest to assess in terms of non-failure: failure is avoided when either the task ends before the outage or begins after it.  In terms of $x$ and $y$, this event consists of all combinations $(x,y)$ for which
$$\text{Non-failure: } y + 1/2 \le x \text{ or } y \ge x + 2.$$
This figure plots the non-failure points in blue:

The numbers $2$ and $1/2$ are so small compared to $500$ that it's difficult to see much.  To see the pattern, let's plot the same problem where the database outage is much longer; say $\eta=100$ minutes, not $2$; and the task duration is also much longer but still differs from the outage; say $\xi=40$ minutes, not $1/2$:

Evidently the blue region comprises two disjoint isosceles right triangles. The one at the upper left has sides of length $500 -\eta -\xi$ while the one at the lower right has sides of length $500 - \eta$.  The total area of the set of all relevant $(x,y)$ coordinates is a rectangle (not a square!) of width $500$ and height $500-\eta$.  (Looking at the picture helps us avoid making the mistake of supposing the relevant coordinates are the full $500\times 500$ square.)  For the uniform distribution, then, the chance of non-failure is
$$\Pr(\text{Non-failure}) = \frac{((500 -\eta -\xi)^2 + (500 - \eta)^2)/2}{500(500-\eta)}.$$
Subtract this from $1$ to obtain the chance of failure.  For $\eta=2$ and $\xi=1/2$ it equals $9959/1992000 = 0.49995\%$.
A: Let's define the following notation:


*

*u: starting time of unavailable database

*t: starting time of task


Now consider the following:


*

*The prob. density that $U=u$ and $T=t$ is given by $f(u, t) = f_u(u) \cdot f_t(t)$, because the two random variables are independent. Furthermore, we got the marginal prob. density $f_u(u) = \int dt\; f(u, t) $ and similarly for $f_t(t)$.

*If the update must be finished after 500min, the starting time of the unavailable database must be 2min before the end. Hence, $U\sim \textrm{Uniform}(0,500-2)$. Therefore, $f_u(u) = \frac{1}{498}$, which is independent of the value $u$.

*Similarly, $T\sim \textrm{Uniform}(0,500-0.5)$. Therefore, $f_t(t) = \frac{1}{499.5}$.

*Now let's use the law of total prob. 
$$P(\textrm{fail}) = P(\textrm{fail} | t\le u) P(t \le u) + P(\textrm{fail} | t\ge u) P(t \ge u)$$ and let's consider each term separately:


*

*$P(\textrm{fail} | t\le u) = P(u\le t+0.5 | t\le u) = \frac{P(u\le t+0.5)}{P(t\le u)}$, where we used Baye's rule the definition of conditional probability (EDITED) .

*Similarly we express $P(\textrm{fail} | t\ge u)$. However, now we have to take the 2min into account.



So we are left with terms like $P(u\le t+0.5)$, which we calculate using the marginal prob. densities from (1) by integration.
