text stringlengths 0 357 |
|---|
{ |
while (1) { |
pthread_mutex_lock(&context->smtpidle_condmutex); |
if (context->smtp_doing_jobs==0) { |
pthread_mutex_unlock(&context->smtpidle_condmutex); |
return; |
} |
pthread_mutex_unlock(&context->smtpidle_condmutex); |
usleep(300*1000); |
} |
} |
} |
/******************************************************************************* |
* Tools |
******************************************************************************/ |
static time_t get_backoff_time_offset(int c_tries) |
{ |
#define MULTIPLY 60 |
#define JOB_RETRIES 17 // results in ~3 weeks for the last backoff timespan |
time_t N = (time_t)pow((double)2, c_tries - 1); |
N = N * MULTIPLY; |
time_t seconds = rand() % (N+1); |
if (seconds<1) { |
seconds = 1; |
} |
return seconds; |
} |
static time_t get_next_wakeup_time(dc_context_t* context, int thread) |
{ |
time_t wakeup_time = 0; |
sqlite3_stmt* stmt = NULL; |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT MIN(desired_timestamp)" |
" FROM jobs" |
" WHERE thread=?;"); |
sqlite3_bind_int(stmt, 1, thread); |
if (sqlite3_step(stmt)==SQLITE_ROW) { |
wakeup_time = sqlite3_column_int(stmt, 0); |
} |
if (wakeup_time==0) { |
wakeup_time = time(NULL) + 10*60; |
} |
sqlite3_finalize(stmt); |
return wakeup_time; |
} |
int dc_job_action_exists(dc_context_t* context, int action) |
{ |
int job_exists = 0; |
sqlite3_stmt* stmt = NULL; |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT id FROM jobs WHERE action=?;"); |
sqlite3_bind_int (stmt, 1, action); |
job_exists = (sqlite3_step(stmt)==SQLITE_ROW); |
sqlite3_finalize(stmt); |
return job_exists; |
} |
void dc_job_add(dc_context_t* context, int action, int foreign_id, const char* param, int delay_seconds) |
{ |
time_t timestamp = time(NULL); |
sqlite3_stmt* stmt = NULL; |
int thread = 0; |
if (action >= DC_IMAP_THREAD && action < DC_IMAP_THREAD+1000) { |
thread = DC_IMAP_THREAD; |
} |
else if (action >= DC_SMTP_THREAD && action < DC_SMTP_THREAD+1000) { |
thread = DC_SMTP_THREAD; |
} |
else { |
return; |
} |
stmt = dc_sqlite3_prepare(context->sql, |
"INSERT INTO jobs (added_timestamp, thread, action, foreign_id, param, desired_timestamp) VALUES (?,?,?,?,?,?);"); |
sqlite3_bind_int64(stmt, 1, timestamp); |
sqlite3_bind_int (stmt, 2, thread); |
sqlite3_bind_int (stmt, 3, action); |
sqlite3_bind_int (stmt, 4, foreign_id); |
sqlite3_bind_text (stmt, 5, param? param : "", -1, SQLITE_STATIC); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.