Update Geary.ImapEngine classes to implement Geary.Logging.Source
This commit is contained in:
parent
9884cd2e6c
commit
dc665d20dd
4 changed files with 60 additions and 34 deletions
|
|
@ -17,7 +17,8 @@
|
|||
* occurs the error will be suppressed and it will be re-attempted
|
||||
* once, to allow for the network dropping out mid-execution.
|
||||
*/
|
||||
internal class Geary.ImapEngine.AccountProcessor : Geary.BaseObject {
|
||||
internal class Geary.ImapEngine.AccountProcessor :
|
||||
Geary.BaseObject, Logging.Source {
|
||||
|
||||
|
||||
// Retry ops after network failures at least once before giving up
|
||||
|
|
@ -38,8 +39,15 @@ internal class Geary.ImapEngine.AccountProcessor : Geary.BaseObject {
|
|||
/** Fired when an error occurs processing an operation. */
|
||||
public signal void operation_error(AccountOperation op, Error error);
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public Logging.Flag logging_flags {
|
||||
get; protected set; default = Logging.Flag.ALL;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public Logging.Source? logging_parent { get { return _logging_parent; } }
|
||||
private weak Logging.Source? _logging_parent = null;
|
||||
|
||||
private string id;
|
||||
|
||||
private bool is_running;
|
||||
|
||||
|
|
@ -50,8 +58,7 @@ internal class Geary.ImapEngine.AccountProcessor : Geary.BaseObject {
|
|||
private GLib.Cancellable? op_cancellable = null;
|
||||
|
||||
|
||||
public AccountProcessor(string id) {
|
||||
this.id = id;
|
||||
public AccountProcessor() {
|
||||
this.queue.allow_duplicates = false;
|
||||
this.is_running = true;
|
||||
this.run.begin();
|
||||
|
|
@ -72,6 +79,20 @@ internal class Geary.ImapEngine.AccountProcessor : Geary.BaseObject {
|
|||
this.queue.clear();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public virtual Logging.State to_logging_state() {
|
||||
return new Logging.State(
|
||||
this,
|
||||
"queued: %d",
|
||||
this.queue.size
|
||||
);
|
||||
}
|
||||
|
||||
/** Sets the processor's logging parent. */
|
||||
internal void set_logging_parent(Logging.Source parent) {
|
||||
this._logging_parent = parent;
|
||||
}
|
||||
|
||||
private async void run() {
|
||||
while (this.is_running) {
|
||||
this.op_cancellable = new GLib.Cancellable();
|
||||
|
|
@ -85,7 +106,7 @@ internal class Geary.ImapEngine.AccountProcessor : Geary.BaseObject {
|
|||
}
|
||||
|
||||
if (op != null) {
|
||||
debug("%s: Executing operation: %s", id, op.to_string());
|
||||
debug("Executing operation: %s", op.to_string());
|
||||
this.current_op = op;
|
||||
|
||||
Error? op_error = null;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
* (version 2.1 or later). See the COPYING file in this distribution.
|
||||
*/
|
||||
|
||||
private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject {
|
||||
private class Geary.ImapEngine.AccountSynchronizer :
|
||||
Geary.BaseObject, Logging.Source {
|
||||
|
||||
|
||||
private weak GenericAccount account { get; private set; }
|
||||
|
|
@ -28,6 +29,26 @@ private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject {
|
|||
this.account.folders_contents_altered.connect(on_folders_contents_altered);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public Logging.Flag logging_flags {
|
||||
get; protected set; default = Logging.Flag.ALL;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public Logging.Source? logging_parent {
|
||||
get { return this.account; }
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public virtual Logging.State to_logging_state() {
|
||||
return new Logging.State(
|
||||
this,
|
||||
"%s, %s",
|
||||
this.account.information.id,
|
||||
this.max_epoch.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
private void send_all(Gee.Collection<Folder> folders, bool became_available) {
|
||||
foreach (Folder folder in folders) {
|
||||
// Only sync folders that:
|
||||
|
|
@ -53,7 +74,7 @@ private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject {
|
|||
try {
|
||||
this.account.queue_operation(op);
|
||||
} catch (Error err) {
|
||||
debug("Failed to queue sync operation: %s", err.message);
|
||||
warning("Failed to queue sync operation: %s", err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -122,7 +143,7 @@ private class Geary.ImapEngine.RefreshFolderSync : FolderOperation {
|
|||
try {
|
||||
yield minimal.open_async(Folder.OpenFlags.NO_DELAY, cancellable);
|
||||
was_opened = true;
|
||||
debug("Synchronising %s", minimal.to_string());
|
||||
debug("Synchronising");
|
||||
yield sync_folder(cancellable);
|
||||
} catch (GLib.IOError.CANCELLED err) {
|
||||
// All good
|
||||
|
|
@ -255,11 +276,7 @@ private class Geary.ImapEngine.CheckFolderSync : RefreshFolderSync {
|
|||
next_epoch = prefetch_max_epoch;
|
||||
}
|
||||
|
||||
debug(
|
||||
"Synchronising %s to: %s",
|
||||
folder.to_string(),
|
||||
next_epoch.to_string()
|
||||
);
|
||||
debug("Fetching to: %s", next_epoch.to_string());
|
||||
|
||||
if (local_count < this.folder.properties.email_total &&
|
||||
next_epoch.compare(prefetch_max_epoch) >= 0) {
|
||||
|
|
@ -295,14 +312,7 @@ private class Geary.ImapEngine.CheckFolderSync : RefreshFolderSync {
|
|||
Geary.Email? current_oldest,
|
||||
Cancellable cancellable)
|
||||
throws Error {
|
||||
// Expand the vector up until the given epoch
|
||||
Logging.debug(
|
||||
Logging.Flag.PERIODIC,
|
||||
"Synchronizing %s:%s to %s",
|
||||
this.account.to_string(),
|
||||
this.folder.to_string(),
|
||||
next_epoch.to_string()
|
||||
);
|
||||
debug("Expanding vector to %s", next_epoch.to_string());
|
||||
return yield ((MinimalFolder) this.folder).find_earliest_email_async(
|
||||
next_epoch,
|
||||
(current_oldest != null) ? current_oldest.id : null,
|
||||
|
|
@ -323,11 +333,8 @@ private class Geary.ImapEngine.CheckFolderSync : RefreshFolderSync {
|
|||
// marker of age
|
||||
Geary.EmailIdentifier? id =
|
||||
(current_oldest != null) ? current_oldest.id : null;
|
||||
Logging.debug(
|
||||
Logging.Flag.PERIODIC,
|
||||
"Unable to locate epoch messages on remote folder %s:%s%s, fetching one past oldest...",
|
||||
this.account.to_string(),
|
||||
this.folder.to_string(),
|
||||
debug(
|
||||
"Unable to locate epoch messages on remote folder%s, fetching one past oldest...",
|
||||
(id != null) ? " earlier than oldest local" : ""
|
||||
);
|
||||
yield this.folder.list_email_by_id_async(
|
||||
|
|
@ -342,12 +349,9 @@ private class Geary.ImapEngine.CheckFolderSync : RefreshFolderSync {
|
|||
private async void expand_complete_vector(Cancellable cancellable)
|
||||
throws Error {
|
||||
// past max_epoch, so just pull in everything and be done with it
|
||||
Logging.debug(
|
||||
Logging.Flag.PERIODIC,
|
||||
"Synchronization reached max epoch of %s, fetching all mail from %s:%s",
|
||||
this.sync_max_epoch.to_string(),
|
||||
this.account.to_string(),
|
||||
this.folder.to_string()
|
||||
debug(
|
||||
"Reached max epoch of %s, fetching all mail",
|
||||
this.sync_max_epoch.to_string()
|
||||
);
|
||||
|
||||
// Per the contract for list_email_by_id_async, we need to
|
||||
|
|
|
|||
|
|
@ -131,8 +131,9 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
|
|||
this.open_cancellable = new Cancellable();
|
||||
this.remote_ready_lock = new Nonblocking.Semaphore(this.open_cancellable);
|
||||
|
||||
this.processor = new AccountProcessor(this.to_string());
|
||||
this.processor = new AccountProcessor();
|
||||
this.processor.operation_error.connect(on_operation_error);
|
||||
this.processor.set_logging_parent(this);
|
||||
|
||||
try {
|
||||
yield this.local.open_async(cancellable);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class Geary.ImapEngine.AccountProcessorTest : TestCase {
|
|||
new RFC822.MailboxAddress(null, "test1@example.com")
|
||||
);
|
||||
this.account = new Geary.MockAccount(this.info);
|
||||
this.processor = new AccountProcessor("processor");
|
||||
this.processor = new AccountProcessor();
|
||||
|
||||
this.succeeded = 0;
|
||||
this.failed = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue