Skip to content

Commit

Permalink
manually queue tasks from settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
lardbit committed Oct 16, 2021
1 parent 71b4728 commit 49bb1f4
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/frontend/src/app/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class ApiService {
API_URL_IMPORT_MEDIA_TV = '/api/import/media/tv/';
API_URL_IMPORT_MEDIA_MOVIE = '/api/import/media/movie/';
API_URL_OPEN_SUBTITLES_AUTH = '/api/open-subtitles/auth/';
API_URL_QUEUE_TASK = '/api/queue-task/';

SEARCH_MEDIA_TYPE_TV = 'tv';
SEARCH_MEDIA_TYPE_MOVIE = 'movie';
Expand Down Expand Up @@ -796,6 +797,12 @@ export class ApiService {
return this.http.post(url, null, {headers: this._requestHeaders()});
}

public queueTask(task: string) {
const httpParams = new HttpParams({fromObject: { task: task }});
const url = this.API_URL_QUEUE_TASK;
return this.http.post(url, {params: httpParams, headers: this._requestHeaders()});
}

protected _initWebSocket() {

// we can't rely on the server's websocket url because it may be "nefarious" when run in a docker stack,
Expand Down
15 changes: 15 additions & 0 deletions src/frontend/src/app/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,21 @@
</div>
</div>
</div>
<div class="col-12 col-sm-6 col-md-4">
<ngx-loading [show]="isLoading"></ngx-loading>
<div class="card">
<div class="card-header">Tasks</div>
<div class="card-body">
<div class="card-title">Tasks automatically run on a schedule, but you can run them here manually</div>
<button type="button" class="d-block btn btn-sm btn-outline-primary my-1" (click)="queueTask('completed_media')">Process Completed Media</button>
<button type="button" class="d-block btn btn-sm btn-outline-primary my-1" (click)="queueTask('wanted_media')">Process Wanted Media</button>
<button type="button" class="d-block btn btn-sm btn-outline-primary my-1" (click)="queueTask('wanted_tv_seasons')">Wanted TV Seasons Task</button>
<button type="button" class="d-block btn btn-sm btn-outline-primary my-1" (click)="queueTask('auto_watch_tv_seasons')">Auto Watch New TV Seasons</button>
<button type="button" class="d-block btn btn-sm btn-outline-primary my-1" (click)="queueTask('refresh_tmdb_settings')">Refresh TMDB Settings</button>
<button type="button" class="d-block btn btn-sm btn-outline-primary my-1" (click)="queueTask('populate_release_dates')">Populate Release Dates</button>
</div>
</div>
</div>
</div>
</form>
<footer class="d-flex justify-content-end">
Expand Down
15 changes: 15 additions & 0 deletions src/frontend/src/app/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
public users: any[];
public form;
public isSaving = false;
public isLoading = false;
public isVeryingJackettIndexers = false;
public gitCommit = '';
public authenticateOpenSubtitles$: Subscription;
Expand Down Expand Up @@ -228,6 +229,20 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
);
}

public queueTask(task: string): void {
this.isLoading = true;
this.apiService.queueTask(task).subscribe(
(data) => {
this.toastr.success(`Successfully queued task ${task}`);
this.isLoading = false;
}, (error => {
this.toastr.error(`Error queueing task ${task}`);
this.isLoading = false;
console.error(error);
})
);
}

protected _saveSettings(): Observable<any> {
this.isSaving = true;

Expand Down
3 changes: 2 additions & 1 deletion src/nefarious/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
path('quality-profiles/', views.QualityProfilesView.as_view()),
path('auth/', views.ObtainAuthTokenView.as_view()), # authenticates user and returns token
path('git-commit/', views.GitCommitView.as_view()), # returns this app's git commit
path('open-subtitles/auth/', views.OpenSubtitlesAuth.as_view()), # auths against open subtitles
path('open-subtitles/auth/', views.OpenSubtitlesAuthView.as_view()), # auths against open subtitles
path('queue-task/', views.QueueTaskView.as_view()), # queues task
]
28 changes: 26 additions & 2 deletions src/nefarious/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
from nefarious.opensubtitles import OpenSubtitles
from nefarious.search import SEARCH_MEDIA_TYPE_MOVIE, SEARCH_MEDIA_TYPE_TV, SearchTorrents
from nefarious.quality import PROFILES
from nefarious.tasks import import_library_task
from nefarious.tasks import (
import_library_task, completed_media_task, wanted_media_task, auto_watch_new_seasons_task,
refresh_tmdb_configuration, wanted_tv_season_task, populate_release_dates_task,
)
from nefarious.transmission import get_transmission_client
from nefarious.tmdb import get_tmdb_client
from nefarious.utils import trace_torrent_url, swap_jackett_host, is_magnet_url, logger_foreground
Expand Down Expand Up @@ -490,11 +493,32 @@ def post(self, request, media_type):
return Response({'success': True})


class OpenSubtitlesAuth(views.APIView):
class OpenSubtitlesAuthView(views.APIView):

def post(self, request):
open_subtitles = OpenSubtitles()
authed = open_subtitles.auth()
if not authed:
return Response({'success': False, 'error': open_subtitles.error_message})
return Response({'success': True})


class QueueTaskView(views.APIView):

def post(self, request):
assert 'task' in request.data, 'missing task name'

if request.data['task'] == 'completed_media':
completed_media_task.delay()
elif request.data['task'] == 'wanted_media':
wanted_media_task.delay()
elif request.data['task'] == 'wanted_tv_seasons':
wanted_tv_season_task.delay()
elif request.data['task'] == 'auto_watch_tv_seasons':
auto_watch_new_seasons_task.delay()
elif request.data['task'] == 'refresh_tmdb_settings':
refresh_tmdb_configuration.delay()
elif request.data['task'] == 'populate_release_dates':
populate_release_dates_task.delay()

return Response({'success': True})

0 comments on commit 49bb1f4

Please sign in to comment.