Skip to content

Commit 4b07277

Browse files
committed
Remove index update jobs
1 parent 6e45dc8 commit 4b07277

File tree

12 files changed

+9
-595
lines changed

12 files changed

+9
-595
lines changed

.tools/Bible.Alarm.AudioLinksHarvestor/Bible.Alarm.AudioLinksHarvestor.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="AWSSDK.S3" Version="4.0.16.2" />
1211
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.1" />
1312
<PackageReference Include="Polly" Version="8.6.5" />
1413
<PackageReference Include="Serilog" Version="4.3.0" />

.tools/Bible.Alarm.AudioLinksHarvestor/Program.cs

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
using System.Linq;
99
using System.Text.Json;
1010
using System.Threading.Tasks;
11-
using Amazon;
12-
using Amazon.S3;
13-
using Amazon.S3.Model;
1411
using Bible.Alarm.AudioLinksHarvestor.Harvestors.Bible;
1512
using Bible.Alarm.AudioLinksHarvestor.Harvestors.Drama;
1613
using Bible.Alarm.AudioLinksHarvestor.Harvestors.Music;
@@ -227,14 +224,8 @@ public static async Task<int> Main(string[] args)
227224
throw new ApplicationException($"New index file size ({newIndexFileSize / 1024}kb) is significantly smaller than old index file size ({originalIndexFileSize / 1024}kb). This could indicate data loss.");
228225
}
229226

230-
if (!isTestRun)
231-
{
232-
await PublishToCloudFront(logger);
233-
}
234-
else
235-
{
236-
logger.Information("=== TEST RUN: Skipping cloud publishing ===");
237-
}
227+
// Media index is now packaged with the app only, updated on app updates
228+
// No longer publishing to AWS S3/CloudFront
238229
}
239230
catch (Exception ex)
240231
{
@@ -320,53 +311,4 @@ private static void DeleteDirectory(string path)
320311
}
321312
}
322313

323-
private static async Task PublishToCloudFront(ILogger logger)
324-
{
325-
var keyPrefix = "bible-alarm/media-index";
326-
var bucketName = "jthomas.info";
327-
using var s3Client = new AmazonS3Client(RegionEndpoint.GetBySystemName("ca-central-1"));
328-
329-
var listObjectsResponse = await s3Client.ListObjectsAsync(new ListObjectsRequest
330-
{
331-
Prefix = $"{keyPrefix}/",
332-
BucketName = bucketName
333-
});
334-
335-
var utcTime = DateTime.UtcNow;
336-
// Use new file name format with prefix (e.g., "v2-7-1-2024.zip")
337-
var fileName = $"{AppConstants.ApiEndpoints.MediaIndexFileNamePrefix}{utcTime.Day}-{utcTime.Month}-{utcTime.Year}.zip";
338-
var keyName = $"{keyPrefix}/{fileName}";
339-
await s3Client.PutObjectAsync(new PutObjectRequest
340-
{
341-
BucketName = bucketName,
342-
Key = keyName,
343-
FilePath = $"{DirectoryHelper.IndexDirectory}/index.zip",
344-
345-
});
346-
347-
// Only delete files with the new prefix format to preserve pre-migration files
348-
if (listObjectsResponse.S3Objects.Count > 0)
349-
{
350-
var deleteObjectsRequest = new DeleteObjectsRequest
351-
{
352-
BucketName = bucketName
353-
};
354-
355-
listObjectsResponse.S3Objects.ForEach(x =>
356-
{
357-
// Only delete files with the new prefix format (v2-), preserve old format files
358-
if (x.Key != keyName && x.Key.Contains($"{keyPrefix}/{AppConstants.ApiEndpoints.MediaIndexFileNamePrefix}"))
359-
{
360-
deleteObjectsRequest.AddKey(x.Key);
361-
}
362-
});
363-
364-
if (deleteObjectsRequest.Objects.Count > 0)
365-
{
366-
await s3Client.DeleteObjectsAsync(deleteObjectsRequest);
367-
}
368-
369-
}
370-
371-
}
372314
}

src/Bible.Alarm/Platforms/Android/Services/Bootstrap/AndroidPlatformBootstrapService.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ private static void CreateNotificationChannel()
121121
private static void VerifyBackgroundTasks(Context context)
122122
{
123123
SchedulerSetupTask(context);
124-
UpdateMediaIndexJobTask(context);
125124
}
126125

127126
private static bool SchedulerSetupTask(Context context)
@@ -151,31 +150,4 @@ private static bool SchedulerSetupTask(Context context)
151150
return success;
152151
}
153152

154-
private static bool UpdateMediaIndexJobTask(Context context)
155-
{
156-
// Update media index every 24 hours (1440 minutes)
157-
using var jobBuilder = context.CreateJobBuilderUsingJobId<UpdateMediaIndexJob>(UpdateMediaIndexJob.JobId, 1440);
158-
var jobInfo = jobBuilder.Build();
159-
160-
var jobScheduler = (JobScheduler?)context.GetSystemService(Context.JobSchedulerService);
161-
if (jobScheduler == null || jobInfo == null)
162-
{
163-
logger.Warning("Failed to schedule UpdateMediaIndexJob - JobScheduler or JobInfo is null");
164-
return false;
165-
}
166-
167-
var scheduleResult = jobScheduler.Schedule(jobInfo);
168-
var success = JobScheduler.ResultSuccess == scheduleResult;
169-
170-
if (success)
171-
{
172-
logger.Debug("UpdateMediaIndexJob scheduled successfully");
173-
}
174-
else
175-
{
176-
logger.Warning("Failed to schedule UpdateMediaIndexJob - result: {Result}", scheduleResult);
177-
}
178-
179-
return success;
180-
}
181153
}

src/Bible.Alarm/Platforms/Android/Services/Helpers/AndroidBootstrapHelper.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public static async Task Initialize(ILogger logger, Context context, AndroidAppl
4343
private static void VerifyBackgroundTasks(Context context)
4444
{
4545
SchedulerSetupTask(context);
46-
UpdateMediaIndexJobTask(context);
4746
}
4847

4948
private static bool SchedulerSetupTask(Context context)
@@ -68,28 +67,6 @@ private static bool SchedulerSetupTask(Context context)
6867
}
6968

7069

71-
private static bool UpdateMediaIndexJobTask(Context context)
72-
{
73-
// Update media index every 24 hours (1440 minutes)
74-
using var jobBuilder = context.CreateJobBuilderUsingJobId<UpdateMediaIndexJob>(UpdateMediaIndexJob.JobId, 1440);
75-
var jobInfo = jobBuilder.Build();
76-
77-
var jobScheduler = (JobScheduler)context.GetSystemService(Context.JobSchedulerService);
78-
if (jobScheduler == null)
79-
{
80-
return false;
81-
}
82-
83-
if (jobInfo == null)
84-
{
85-
return false;
86-
}
87-
88-
var scheduleResult = jobScheduler.Schedule(jobInfo);
89-
90-
return JobScheduler.ResultSuccess == scheduleResult;
91-
92-
}
9370

9471
private static void CreateNotificationChannel()
9572
{

src/Bible.Alarm/Platforms/Android/Services/Jobs/UpdateMediaIndexJob.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/Bible.Alarm/Platforms/Windows/Helpers/WindowsBootstrapHelper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ private static Task SetupBackgroundTask()
3939
IsBackgroundTaskEnabled = true;
4040

4141
// Note: Media index update background task handler is available at:
42-
// Platforms.Windows.Services.BackgroundTasks.UpdateMediaIndexBackgroundTask
4342
// This can be called from Windows Task Scheduler or app lifecycle events
4443
// WinUI 3 doesn't support UWP background tasks the same way as UWP
4544

src/Bible.Alarm/Platforms/Windows/Helpers/WindowsPeriodicBackgroundTasks.cs

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#nullable enable
22

3-
using Bible.Alarm.Platforms.Windows.Services.BackgroundTasks;
43
using Bible.Alarm.Services.Scheduler.Interfaces;
54
using Serilog;
65

@@ -9,7 +8,6 @@ namespace Bible.Alarm.Platforms.Windows.Helpers;
98
/// <summary>
109
/// Manages periodic background tasks for Windows (similar to Android JobScheduler).
1110
/// - SchedulerService: Runs every 30 minutes (like Android SchedulerJob)
12-
/// - UpdateMediaIndexBackgroundTask: Runs every 24 hours (like Android UpdateMediaIndexJob)
1311
/// </summary>
1412
public sealed class WindowsPeriodicBackgroundTasks : IDisposable
1513
{
@@ -18,7 +16,6 @@ public sealed class WindowsPeriodicBackgroundTasks : IDisposable
1816

1917
// Periodic timers for Windows background tasks
2018
private PeriodicTimer? schedulerTimer; // Runs every 30 minutes (like Android SchedulerJob)
21-
private PeriodicTimer? mediaIndexTimer; // Runs every 24 hours (like Android UpdateMediaIndexJob)
2219
private CancellationTokenSource? timersCancellationTokenSource;
2320
private readonly object timersLock = new();
2421
private bool isDisposed;
@@ -52,13 +49,7 @@ public void Start()
5249
schedulerTimer = new PeriodicTimer(TimeSpan.FromMinutes(30));
5350
_ = RunSchedulerTaskAsync(schedulerTimer, cancellationToken);
5451

55-
// Run media index update task immediately on start
56-
_ = RunMediaIndexUpdateTaskOnceAsync(cancellationToken);
57-
// Then start periodic timer (every 24 hours, like Android UpdateMediaIndexJob)
58-
mediaIndexTimer = new PeriodicTimer(TimeSpan.FromHours(24));
59-
_ = RunMediaIndexUpdateTaskAsync(mediaIndexTimer, cancellationToken);
60-
61-
logger.Information("Started periodic background tasks for Windows: Scheduler (30 min), MediaIndex (24 hours) - running immediately on start");
52+
logger.Information("Started periodic background tasks for Windows: Scheduler (30 min) - running immediately on start");
6253
}
6354
}
6455

@@ -111,52 +102,6 @@ private async Task RunSchedulerTaskAsync(PeriodicTimer timer, CancellationToken
111102
}
112103
}
113104

114-
/// <summary>
115-
/// Runs the media index update task once immediately on app start.
116-
/// </summary>
117-
private async Task RunMediaIndexUpdateTaskOnceAsync(CancellationToken cancellationToken)
118-
{
119-
try
120-
{
121-
logger.Debug("Running media index update task immediately on app start");
122-
await UpdateMediaIndexBackgroundTask.HandleAsync();
123-
}
124-
catch (Exception e)
125-
{
126-
logger.Error(e, "Error running media index update task on app start");
127-
}
128-
}
129-
130-
/// <summary>
131-
/// Runs the media index update task periodically (every 24 hours, like Android UpdateMediaIndexJob)
132-
/// </summary>
133-
private async Task RunMediaIndexUpdateTaskAsync(PeriodicTimer timer, CancellationToken cancellationToken)
134-
{
135-
try
136-
{
137-
while (await timer.WaitForNextTickAsync(cancellationToken))
138-
{
139-
try
140-
{
141-
logger.Debug("Windows periodic media index update task running (every 24 hours)");
142-
await UpdateMediaIndexBackgroundTask.HandleAsync();
143-
}
144-
catch (Exception e)
145-
{
146-
logger.Error(e, "Error in Windows periodic media index update task");
147-
}
148-
}
149-
}
150-
catch (OperationCanceledException)
151-
{
152-
// Expected when timer is stopped
153-
logger.Debug("Windows media index update timer stopped");
154-
}
155-
catch (Exception e)
156-
{
157-
logger.Error(e, "Unexpected error in Windows media index update timer");
158-
}
159-
}
160105

161106
public void Dispose()
162107
{
@@ -177,9 +122,6 @@ public void Dispose()
177122
schedulerTimer?.Dispose();
178123
schedulerTimer = null;
179124

180-
mediaIndexTimer?.Dispose();
181-
mediaIndexTimer = null;
182-
183125
logger.Debug("Stopped and disposed Windows periodic background task timers");
184126
}
185127
}

src/Bible.Alarm/Platforms/Windows/Services/BackgroundTasks/UpdateMediaIndexBackgroundTask.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)